I'm trying to dynamically build a form by looping over a set of fields that have a renderer attribute, which is used to tell what widget should be used to renderer them.
The problem I'm facing is when the widget is a select element. In this case, the nested f:selectItems load their data from a bean that, if I understand well the documentation, cannot be specified at runtime. Thus, I have hardcoded the bean that provides the data to the select boxes (dataProviderBean.selectItems in my simplified example below). But when the form is rendering, I haven't found any mean by which dataProviderBean can know which select element is being populated.
What's the best approach for solving this problem ?
<h:dataTable var="field" value="#{fieldSet}"> <h:column> #{field.name} </h:column> <h:column> <h:inputText value="#{field.value}" rendered="#{field.renderer.isInputText}"/> <h:selectManyListbox value="#{field.value}" rendered="#{field.renderer.isManyListBox}"> <f:selectItems value="#{dataProviderBean.selectItems}"/> </h:selectManyListbox> <h:selectManyCheckbox value="#{field.value}" rendered="#{field.renderer.isManyselectManyCheckbox}"> <f:selectItems value="#{dataProviderBean.selectItems}"/> </h:selectManyCheckbox> </h:column> </h:dataTable>
You can pass a parameter using JBoss EL like #{dataProviderBean.getSelectItems('foo')}