如何提交下拉列表的选定选项?

时间:2013-03-13 04:30:37

标签: jsp java-ee struts2

我有以下代码向用户显示一个选择选项的列表,它正确显示了列表选项,但是当选择了一个选项并且提交了表单时,它会遇到以下错误。

错误

 Caused by: tag 'select', field 'list', name 'developerID': The requested list key 
 'listOfdevelopers' could not be resolved as a collection/array/map/enumeration/iterator type. 
 Example: people or people.{name} - [unknown location]

JSP

 <s:form ...>
  <s:select name="developerID"
                      label="developerID"
                      list="listOfdevelopers"
                      value="%{development.developerID}"
                      />
 </s:form>

我的代码

....
private Map listOfdevelopers;
private Development development = new Development();

public Map getListOfdevelopers() {
    return listOfdevelopers;
}

public void setListOfdevelopers(Map listOfdevelopers) {
    this.listOfdevelopers = listOfdevelopers;
}

public Development getDevelopment() {
    return development;
}

public void setDevelopment(Development development) {
    this.development = development;
}

@Override
public Development getModel() {
    return this.development;
}
...    

2 个答案:

答案 0 :(得分:0)

<s:select list="listOfdevelopers"
                        id="developerID"
                         name="developerID"
                             label="developerID"
                             headerKey=""
                              headerValue="Please choose one."
                            value="%{development.developerID}"
                      />

例如

<s:select list="genderList"
          id="gender"
          name="gender"
          cssClass="listmenu validate-selection"
          listKey="name"
          listValue="details"
          headerKey=""
          value="userInfo.userPersonalInfo.gender"
          headerValue="Please choose one."
          ></s:select>

答案 1 :(得分:-1)

实际上问题出在您的 s:select ,此处的值标记导致问题。

试试这个

    <s:select list="listOfdevelopers" 
              name="developerID"
              headerKey="-1" 
              headerValue="Select Any Developer"
              listKey="developerID"               // your collection_element
              listValue="developer_name"          // your collection_element
    />