gpt4 book ai didi

java - 标签 'select' ,字段 'list' ,名称 'uuid' : The requested list key 'deptList' could not be resolved as a collection/array/map/enumeration/iterator type

转载 作者:行者123 更新时间:2023-11-30 07:34:33 33 4
gpt4 key购买 nike

我有一个struts2问题,它只在出现验证错误时发生(当我第一次加载页面时不会发生,如果验证错误没有发生则不会发生)如果我删除选择标签,它工作正常,并且在我提交表单后显示验证错误消息,但我需要这些选择,并且它们具有来自数据库的动态信息,因此每次显示表单时都需要预加载它们。我尝试将 deptListroleList 放入 valuestack 或将它们放入 session 中,同样的事情发生了。

这是Action类代码的一部分:

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 报告中的错误:

tag 'select', field 'list', name 'empModel.deptModel.uuid': The requested list key 'deptList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{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>

最佳答案

当您提交表单时,验证错误会阻止操作执行,因为workflow拦截器返回结果INPUT。您可以通过在操作方法上添加注释来配置此拦截器

@InputConfig(methodName="input")
public String save(){
if(empModel.getUuid() == null ){
empEbi.save(empModel,roleUuids);
}else{
empEbi.update(empModel,roleUuids);
}
return TO_LIST;
}

它会从拦截器调用方法input来初始化列表,然后再返回INPUT结果。

关于java - 标签 'select' ,字段 'list' ,名称 'uuid' : The requested list key 'deptList' could not be resolved as a collection/array/map/enumeration/iterator type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35586826/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com