I am adding, dynamically, text field when a value is selected from a (static)dropdown. There are other static fields in the JSF/JSP page too.
My problem is : On pressing a command button, in my action method, i am not able to get the user-entered value of the dynamic text field. I am able to get the values from the static fields.
I create the dynamic text field by creating a Panel and adding the HtmlInput text field in my managed bean. I then do a Value binding for this field. I bind it to a variable in the managed bean. But i am not getting any value of this variable. PLEASE HELP.
here is the code :
JSP <h:panelGrid id="panelgrid1" columns="2">
<h:panelGroup id="panelgroup1" binding="#{TradeDetailsPageBean.groupPanel}">
...............
....................
Here the dynamic input fields will be added.
</h:panelGroup>
</h:panelGrid>
................
.............
<div class="field">
<span>
<h:selectOneMenu id="filterName" onchange="this.form.submit()" styleClass="formInputs" value="#{TradeDetailsPageBean.filterName}" valueChangeListener="#{TradeDetailsPageBean.setFilterOnChange}">
<f:selectItems value="# TradeDetailsPageBean.availableTradeFilters}"/>
</h:selectOneMenu>
</span>
</div>
<div class="field">
<span><h:commandButton id="searchButton" action="#{TradeDetailsPageBean.searchDetailsResultsAction}"styleClass="btns" value="Search" />
</span>
</div>
Backing bean code:
....
private
String textVal; // the String attached to the dynamic input field
public String getTextVal()
{
return textVal;
}
public void setTextVal(String textVal)
{
this.textVal = textVal;
}
public void setFilterOnChange(ValueChangeEvent valChangeEvent)
{
String filterName = (String) valChangeEvent.getNewValue();
setFilterName(filterName);
setTradeFilter(getSelectedFilter());
populatePanel(filterName);
FacesContext.getCurrentInstance().renderResponse();
}
private void populatePanel(String filterName)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
FilterTO fltTO = (FilterTO) htAvailableTradeFilters.get(filterName);
List rules = fltTO.getRules();
groupPanel.getChildren().clear();
groupPanel.setRendered(true);
if(rules != null) {
for(int i = 0; i < rules.size();i++)
{
FilterRuleTO fltRule = (FilterRuleTO)rules.get(i);
String valueType = fltRule.getValueType();
if(valueType != null && valueType.equalsIgnoreCase("prompt"))
{
UIOutput label = new UIOutput();
label.setValue(fltRule.getSubject()+"?");
groupPanel.getChildren().add(label);
//UIInput inputText = new UIInput();
HtmlInputText inputText = new HtmlInputText();
inputText.setId(fltRule.getSubject());
//inputText.encodeEnd(facesContext);
inputText.saveState(facesContext);
inputText.getAttributes().put("styleClass","formInputs");
ValueBinding inputValBind = application.createValueBinding("#{TradeDetailsPageBean.textVal}");
inputText.setValueBinding("value"+i,inputValBind);
groupPanel.getChildren().add(inputText);
}
}
}
public String searchDetailsResultsAction()
{
System.out.println("The input text field entered value is "+textVal+" hello "+getTextVal()); // This is coming as null
}