This questions seems to be so simple, yet I didn't find the mistake.
Ok, here we go: I have a form with a List of IPs (whatever),
IP n: [INPUT-FIELD] [Button "Add"]
IP n+1: [INPUT-FIELD] [Button "Add"]
These IPs exist right from the start.
They are initialized in the Constructor of the Managed Bean.
When I click on the "Add" Button, the current IP is validated. After that I add another entry to my java.util.List and another line in the JSF form appears:
IP n+2: [INPUT-Field] [Button "Add"]
and so on.
Adding a line (with a new IP) and validating the current IP work perfect for the existing values IP n and IP n+1, but validating and adding does NOT work with the dynamically added IP n+2. Neither validating the dynamically generated input field works nor adding another line with the newly created "Add"-Button.
What am I doing wrong?
<h:form id="frmSpecial" prependId="false">
<h:panelGroup id="tblDestFw">
<c:forEach items="#{bean.fwdest}" var="fwdest">
IP: <h:inputText value="#{fwdest.ip}" validator="#{bean.validateIP}"/>
<h:commandButton action="#{bean.addFwDest()}"
value=">>" title="Add another line">
<f:ajax execute="@this" render="tblDestFw"/>
</h:commandButton>
<br/>
</c:forEach>
</h:panelGroup>
</h:form>
@ManagedBean(name = "bean")
@ViewScoped
public class EnterNewSystemFW implements Serializable {
List<FirewallDest> fwdest;
public EnterNewSystemFW() {
fwdest.add(new FirewallDest("N"));
fwdest.add(new FirewallDest("N+1"));
}
public void addFwDest() {
fwdest.add(new FirewallDest());
}
}
Thanks.
Bernd