I have a form with around 90 items. Is there a way to collect the generated values without having that many setters on the server side? can't I parse a list/array/object that I generate with JavaScript? It would help me a lot.
Many thanks, Martijn
I have a form with around 90 items. Is there a way to collect the generated values without having that many setters on the server side? can't I parse a list/array/object that I generate with JavaScript? It would help me a lot.
Many thanks, Martijn
Create a Map
property.
@ManagedBean
@ViewScoped
public class Bean {
private Map<String, String> selectedItems = new HashMap<String, String>();
public Map<String, String> getSelectedItems() {
return selectedItems;
}
// ...
}
Which can be used as
<h:selectOneMenu value="#{bean.selectedItems.one}">
...
</h:selectOneMenu>
or
<h:selectOneMenu value="#{bean.selectedItems['one']}">
...
</h:selectOneMenu>
Here one
becomes the map key and the selected item becomes the map value.
(yes, no setter is required!)
Update an alternative is to have a <h:dataTable>
with a <h:selectOneMenu>
in the column. This way you can just use a single List<Item>
getter (no one setter is required). See also the answer on this question for an example.