1

My Idea/Requirement is to render dynamically generated jsf page and bind/capture the user filled data and save into db. Dynamically rendering part is working fine but not able to capture the user filled data back to my managedbean. I am using Jsf 2.1.

LoginManagedBean.java (requestscoped)


private String fieldName;
//getters and setters

public String trytry()
{
    HtmlInputText inputText = (HtmlInputText) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);
    inputText.setId("it");
    inputText.setValueExpression("value", FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),"#{loginmb.keyValueMap['" + inputText.getId() + "']}", String.class));

    panelGroupChilds.add(inputText);
    grid.getChildren().add(panelGroupTextbox);

    return "done";
}


public String save() {
        System.out.println("fieldName ---  " + this.fieldName);
        return "save";

    }


done.xhtml (dynamically rendered page)

<h:panelGrid  binding="#{loginmb.docGridElems}"></h:panelGrid>


    <h:commandButton id="cndB" value="SAVE" action="#{loginmb.save()}"></h:commandButton>

I am able to see the rendered textbox in done.xhtml but on submit the save button, I am not able to get the value of "feildName" (it is null). I am not able to find where i went wrong.

I even tried to bind the Map but could not able to get it.

Jyothsna
  • 11
  • 3
  • Sorry missed the main part... – Jyothsna Aug 05 '15 at 10:56
  • You're going in the wrong direction. You should use a `` instead of a ``. See also a.o. http://stackoverflow.com/questions/3409053/how-to-dynamically-add-jsf-components – BalusC Aug 05 '15 at 11:03
  • I want to render my text box in panelGrid, i have tried with value also still facing issue – Jyothsna Aug 05 '15 at 12:25
  • So you actually didn't click and carefully read that link? – BalusC Aug 05 '15 at 12:27
  • Yea I read it...I found the solution...I have changed the scope of my bean to SessionScoped..earlier it was RequestScoped..Thanks for the help!! – Jyothsna Aug 05 '15 at 13:36
  • This "solution" will end up in more trouble. More food for read: http://stackoverflow.com/questions/14911158/how-does-the-binding-attribute-work-in-jsf-when-and-how-should-it-be-used Don't tell in future questions that I haven't warned you. **Do not bind JSF components to a bean**. – BalusC Aug 05 '15 at 13:41
  • Thanks for the link!! It is very Useful...Understood the problem.Will be work on that. – Jyothsna Aug 06 '15 at 04:03

0 Answers0