没有submit()JSF,值更改侦听器无法正常工作

时间:2014-05-22 12:38:19

标签: jsf valuechangelistener

这是我的JSP:

  <h:panelGrid columns="2">

Selected Location : 
    <h:inputText id="emp" value="#{employee.locationCode}" size="20" />

    Select a country {method binding}: 
    <h:selectOneMenu id="empl" value="#{employee.locationCode}" 
        valueChangeListener="#{employee.countryLocationCodeChanged}" onchange="submit()">
        <f:selectItems value="#{employee.locationInMap}" />
    </h:selectOneMenu>
  </h:panelGrid>

我的豆子:     private static Map locationMap;     private String locationCode =“en”; //默认值

static{
    locationMap = new LinkedHashMap<String,String>();
    locationMap.put("United Kingdom", "en"); //label, value
    locationMap.put("French", "fr");
    locationMap.put("German", "de");
    locationMap.put("China", "zh_CN");
    }
public void countryLocationCodeChanged(ValueChangeEvent e){
    //assign new value to localeCode
    setLocationCode(e.getNewValue().toString());

}

public Map<String,String> getLocationInMap() {
    return this.locationMap;
}

public String getLocationCode() {
    return locationCode;
}

public void setLocationCode(String locationCode) {
    this.locationCode = locationCode;
}
public void changeEvent(String locationCode) {
    this.locationCode = locationCode;
}

除此之外,我在jsp中有更多字段。当我选择下拉值时,它会给出非法参数异常。我想submit()正在制作一些问题..任何人都可以提供帮助。提前谢谢..

1 个答案:

答案 0 :(得分:2)

问题在于您的selectItems标记。

<f:selectItems value="#{employee.locationInMap}" />

您无法将整个地图初始化为 selectOneMenu 标记。

只需尝试 entryset ,如下所示:

<f:selectItems value="#{bean.locationInMap.entrySet()}" var="entry" 
itemValue="#{entry.key}" itemLabel="#{entry.value}" />

您可以在selectOneMenu here

上找到更多信息
相关问题