1

I'm dynamically generating a #{materielBean2.nbrsalle} amount of dropdowns:

<c:forEach begin="1" end="#{materielBean2.nbrsalle}" var="i">
    <p:selectOneMenu id="p#{i}" value="#{materielBean2.pole}">
        <f:selectItem itemLabel="Select Pole" itemValue="" />
        <f:selectItems value="#{materielBean2.poles}" />
        <p:ajax event="change" update="s#{i}" listener="#{materielBean2.salleChange(i)}" />
    </p:selectOneMenu>
</c:forEach>

I have a Map<String, String> property where I'd like to save the selected values.

private Map<String, String> selectedPoles = new HashMap<String, String>();

The ajax change listener method is as follows:

public void sallechange(int i) {
    selectedPoles.put(i, pole);
}

How do I get the selected pole value of index i in the listener method?

4

1 回答 1

1

只需将输入值直接绑定到该映射。

<p:selectOneMenu id="p#{i}" value="#{materielBean2.selectedPoles[i]}">

您只需要更改地图以获取整数键。

private Map<Integer, String> selectedPoles = new HashMap<Integer, String>();

或者也许只是使用一个可以以完全相同的方式访问的简单数组。

private String[] selectedPoles = new String[poles.size()];

无论哪种方式,这样你都可以完全摆脱<p:ajax>。JSF 会神奇地为您设置它。

<p:selectOneMenu id="p#{i}" value="#{materielBean2.selectedPoles[i]}">
    <f:selectItem itemLabel="Select Pole" itemValue="" />
    <f:selectItems value="#{materielBean2.poles}" />
</p:selectOneMenu>
于 2013-04-24T17:00:36.457 回答