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

没有submit()JSF,值更改侦听器无法工作,jsf,valuechangelistener,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}"

这是我的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>

选定地点:
选择一个国家{方法绑定}:
我的豆豆: 私有静态地图定位地图; 私有字符串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;
}
静态{
locationMap=新建LinkedHashMap();
locationMap.put(“联合王国”,“en”);//标签,值
地点地图(法语、法语);
位置图。put(“德语”、“de”);
地理位置图。put(“中国”、“中国”);
}
public void countryLocationCodeChanged(ValueChangeEvent e){
//将新值分配给localeCode
setLocationCode(例如getNewValue().toString());
}
公共地图getLocationInMap(){
返回此.locationMap;
}
公共字符串getLocationCode(){
返回位置代码;
}
public void setLocationCode(字符串位置代码){
this.locationCode=位置代码;
}
公共无效更改事件(字符串位置代码){
this.locationCode=位置代码;
}

除此之外,jsp中还有更多字段。当我选择下拉值时,它给出非法参数异常。我想submit()会引起一些问题。。有人能帮忙吗。提前谢谢

问题在于您的selectItems标签

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

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

只需使用entryset进行如下尝试:

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


您可以在selectOneMenu上找到更多信息这可能是个问题,我不确定是否与问题有关。但是,字段的名称为locationMap,获取者为locationInMap。尝试保持这些名称相同。根据TLD,IM获取此异常org.apache.jasper.jaspereException:/EmployeeJSFPage/addEmployee.jsp(246,6)属性var对于标记selectItems无效