I need to build a form dynamically putting inputText field, I'm using this code:
<h:form>
<c:forEach items="#{userBean.getFieldList()}" var="field">
<h:inputText value="#{userBean.getFieldValue(field.name)}" />
</c:forEach>
<h:commandButton value="Login" action="#{userBean.loginAction}" />
</h:form>
the var field is a metadata and not own the field value but only their attribute. So I use
#{userBean.getFieldValue(field.name)}
to get the bean field value. The code above works well if it's used only to view the page. but not on form submit because of it's not possible to setFieldvalue by field name. Is there a way to override the problem? Is there a generale way to dynamically build a back bean edit form?
Bind it to a
Map<String, Object>
property and use the brace notation[]
for the dynamic map key.E.g.
with
The field name becomes the map key and the field value becomes the map value.