Variable number of Input fields
Hi,
I have quite a problem with the following.
Imagine a scenario like storing an item with a name and a variable number of details
The Input Form would look like this:
Name: (inputText)
Detail1: (inputText)
add another detail (as a command link)
Clicking the command link should lead to this:
Name: (inputText)
Detail1: (inputText)
Detail2: (inputText)
add another detail (as a command link)
The bean would have String "name" and String[] or List "details" as properties.
But I have no idea how create the dynamic number of input fields.
My current approach:
Add a field "num_details" to the bean which is incremented when the command link is pressed.
Then:
<% FacesContext fc = FacesContext.getCurrentInstance(); %>
<% Application app = fc.getApplication(); %>
<% myBean = (myBean)app.getVariableResolver().resolveVariable(fc,"myBean"); %>
<%for(int i = 0; i<bean.getNum_details(); i++){ %>
<tr>
<td>Detail<%=i%></td>
<td><h:inputText id="placeholder" value="placeholder" /></td>
</tr>
<%} %>
Works fine so far, the problem is, I did not manage to dynamically set an id or a value.
I think the value should be #{myBean.details[ i ]} but obviously it does not work like this.
I'd be glad if anybody could help me with this, either with a solution to make my approach work, or with a completely different approach.
best regards,
David

