I have a开发者_JAVA技巧 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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论