views:

125

answers:

1

Hi, I'm writing an application that serves as an admin panel using JSF 2.0 and Hibernate. I have a JSP page with a JSF form which elements are added dynamically using javascript (jQuery to be specific). So I cannot make any assumption on how much data do I have to process. I have a managed bean but I don't know how to put the getters and setters for the dynamic fields that I want to save in a database. The solution seems to use a list rather than a single element but how do I use the value tag of the JSF element? Could it be something like this:

<h:form>
<h:inputText id="i1" value="#{UserBean.list}" /> 
<h:inputText id="i2" value="#{UserBean.list}" />
<h:commandbutton id="submit" value="Submit" action="#{UserBean.submit}"/>
</h:form>

And the managed bean:

@ManagedBean(name="UserBean")
@RequestScoped
public class UserBean {

   public UserBean() {
       List<String> list = null;


}
    public List getList() {
    return list;
}
    public List setList(List<String> newlist) {
    list = newList;
}

}

However, the above code does not seem correct and certainly does not work. I need to bind two or more values of the inputtext to the same list. Does anyone have any suggestions how to solve it? Thanks in advance. Regards, sass.

A: 

You can't directly add JSF components dynamically using jQuery. All jQuery can is traversing and manipulating "plain vanilla" HTML DOM tree at the client side. It has totally no notion of the JSF component tree as it is generated and maintained in the server side. JSF in turn knows nothing about the state changes in the HTML DOM tree done by "plain vanilla" jQuery/JavaScript since it doesn't notify JSF on the server side about the changes. JSF relies on the JSF component tree to process form submits, not the HTML DOM tree.

You want to change the JSF component tree dynamically using JSF. Since this is going to be a long story to explain in detail, here are some links to similar questions I answered before to get you started:

BalusC