当前位置: 代码迷 >> J2EE >> struts2的select标签,大家看小弟我用法对不对,如何老是抱错
  详细解决方案

struts2的select标签,大家看小弟我用法对不对,如何老是抱错

热度:242   发布时间:2016-04-22 02:29:11.0
struts2的select标签,大家看我用法对不对,怎么老是抱错
我在Action里定义的
private List<FundsType> fundstype;
private List<ConstruNature> construnature;
private String funds;
private String constru;

都有自己的setter/getter方法

然后再Action的构造函数里,那个FundsType和ConstruNature的构造函数就是让他们的name属性赋值,里面都有一个name属性
public newProjectAction()
{
FundsType[] dt = new FundsType[2];
dt[0] = new FundsType("test");
dt[1] = new FundsType("test2");
ConstruNature[] cn = new ConstruNature[2];
cn[0] = new ConstruNature("test1");
cn[1] = new ConstruNature("test2");
fundstype = Arrays.asList(dt);
construnature = Arrays.asList(cn);
}

接下来是表单的代码
HTML code
<s:form action="newProject.action" method="post"            enctype="application/x-www-form-urlencoded" name="newproject">            <table width="300" border="0">                                <tr>                    <th scope="row">                        资金来源                    </th>                    <td>                        <s:select list="fundstype" name="funds" listKey="name"                            listValue="name" emptyOption="true" headerKey="None"                            headerValue="None" />                    </td>                </tr>                <tr>                    <th scope="row">                        建设类型                    </th>                    <td>                        <s:select list="construnature" name="constru"                            listKey="name" listValue="name"                            emptyOption="true" headerKey="None" headerValue="None" />                    </td>                </tr>                            y


为什么一访问这个页面就会报:
严重: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'funds': The requested list key 'fundstype' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

------解决方案--------------------
<s:select label="Pets"
name="petIds"
list="petDao.pets"
listKey="id"
listValue="name"
multiple="true"
size="3"
required="true"
value="%{petDao.pets.{id}}"
/>

<s:select label="Months"
name="months"
headerKey="-1" headerValue="Select Month"
list="#{'01':'Jan', '02':'Feb', [...]}"
value="selectedMonth"
required="true"
/>

  相关解决方案