I just want to generate dynamically HtmlInputFields, in this sample i just generated 3 fields. In out.xhtml i want to render these components in with ui:repeat and bind them using binding attribute (not value!!).
The loop.index used with varStatus allways fails when using the binding attribute.
exception:
binding="#{loop.index}": Target Unreachable, identifier 'loop' resolved to null
out.xhtml:
<ui:repeat value="#{myBean.htmlInputs}" varStatus="loop" var="bItem">
<!-- THIS WORKS -->
<h:inputText value="#{loop.index}" />
<!-- THIS WORKS -->
<h:inputText value="#{myBean.htmlInputs[0]}" />
<!-- THIS WORKS ALSO -->
<h:inputText binding="#{myBean.htmlInputs[0]}" />
<!-- AND THIS FAILES ?? WHY ?? -->
<h:inputText binding="#{myBean.htmlInputs[loop.index]}" /><p/>
</ui:repeat>
MyBean.java
@Named
@SessionScoped
public class BookingBean implements Serializable {
private List<HtmlInputText> htmlInputs = new ArrayList<>();
@PostConstruct
public void init() {
HtmlInputText hInput;
for (int i=0 ; i<3 ; i++) {
hInput = new HtmlInputText();
hInput.setValue("item #:" + i);
htmlInputs.add( hInput );
}
}
public List<HtmlInputText> getHtmlInputs() {
return htmlInputs;
}
public void setHtmlInputs(List<HtmlInputText> htmlInputs) {
this.htmlInputs = htmlInputs;
}
}
My Question is now: How do i use bindings with dynamically generated JSF Components properly with ui:repeat in JSF 2.2 ?
Thanx