开发者

JSF 2 and JavaScript - submitting a lot of <h:selectOneMenu/> items without that many setters

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜