我有一个struts2问题,它只在出现验证错误时发生(当我第一次加载我的页面时不会发生,如果没有发生验证错误也不会发生)如果我删除选择标签,它工作正常,并且在我提交表单后显示验证错误消息,但我需要这些选择,并且它们具有来自数据库的动态信息,因此每次显示我的表单时都需要预加载它们。我试图将deptList
androleList
放入 valuestack 或将它们放入会话中,同样的事情发生了。
这是动作类代码的一部分:
private List<DeptModel> deptList;
private List<RoleModel> roleList;
public List<RoleModel> getRoleList() {
return roleList;
}
public void setRoleList(List<RoleModel> roleList) {
this.roleList = roleList;
}
public List<DeptModel> getDeptList() {
return deptList;
}
public void setDeptList(List<DeptModel> deptList) {
this.deptList = deptList;
}
public String input() {
roleList = roleEbi.getAll();
this.setRoleList(roleList);
deptList = deptEbi.getAll();
this.setDeptList(deptList);
if (empModel.getUuid() != null) {// for data display when doing modify
empModel = empEbi.get(empModel.getUuid());
roleUuids = new Long[empModel.getRoles().size()];
int i = 0;
for (RoleModel temp : empModel.getRoles()) {
roleUuids[i++] = temp.getUuid();
}
}
return INPUT;
}
public String save(){
if(empModel.getUuid() == null ){
empEbi.save(empModel,roleUuids);
}else{
empEbi.update(empModel,roleUuids);
}
return TO_LIST;
}
这是 JSP 页面:
<s:form action="emp_save" method="post" onsubmit="return checkForm();">
<s:textfield id="username" name="empModel.userName" />
<s:textfield id="password" size="25" name="empModel.pwd"/>
<s:select name="empModel.deptModel.uuid" list="deptList" style="width:190px" listKey="uuid" listValue="name" />
<s:checkboxlist name="roleUuids" list="roleList" listKey="uuid" listValue="name"/>
<a href="javascript:document.forms[0].submit()"><img src="images/save.jpg" border="0" width="81px"/></a>
</s:form>
这是来自 struts 报告的错误:
标签“选择”,字段“列表”,名称“empModel.deptModel.uuid”:请求的列表键“deptList”无法解析为集合/数组/映射/枚举/迭代器类型。示例:人或人。{name}
这是我的验证 xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="empModel.userName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>User Name can not be null ~~~</message>
</field-validator>
</field>
<field name="empModel.pwd">
<field-validator type="requiredstring">
<message>Password can not be null ~~~</message>
</field-validator>
</field>
</validators>