Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Please Help : Problem getting submitted value for dynamic input text field  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
 
Bartender
Posts: 19658
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"PrashantKumar"

Welcome to the JavaRanch!

Our Naming Policy requires that your display name not be a single word. If you could change it to "Prashant Kumar" (as 2 words), we'd really appreciate it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!