JSF选择一个菜单设置错误

时间:2015-07-28 10:16:16

标签: jsf jsf-2 primefaces hashmap selectonemenu

我正在使用选择一个菜单从map<String,Integer>进行选择,但只选择0

 <p:fieldset id="locations" legend="locations" toggleable="false">
        <p:selectOneMenu id="locations" value="#{bean.selectedLocation}" filter="true" filterMatchMode="contains">
            <f:selectItems value="#{bean.availableLocations}"/>
        </p:selectOneMenu>
    </p:fieldset>

我的bean是:

@ManagedBean
@ViewScoped
public class Bean  {
private Map<String, Integer> availableLocations = new HashMap<>();
private int                  selectedLocation   = 1;


public int getSelectedLocation() {
    return selectedLocation;
}
public void setSelectedLocation(int selectedLocation) {
    this.selectedLocation=selectedLocation;
}

@Override
protected void init() {
        availableLocations.clear();
        availableLocations.putAll(Locations.getLocations());
}

}

当我选择任何项目时,只需将0设为selectedLocation

当我将我的fieldset放入表单时,它从未设置任何内容

提前感谢,

1 个答案:

答案 0 :(得分:0)

我发现了问题

添加ajax,问题将解决

<p:ajax event="change" update="@this" />