hxlzpnyist 2011-10-27 12:13
浏览 316
已采纳

struts2 select标签获取action的集合属性值 动态生成下拉菜单 报错

   1.要获取集合list的Action类
public class RoleAction extends ActionSupport {

    private Role role;

    public RoleService roleService;

    public String message;

    public List list;

    public static ActionContext ac = null;

    public String getMessage() {
        return message;
    }

    @Resource(name = "roleService")
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }
    
    public List getList() {
        return list;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public String List() throws Exception {
        /*
         * 浏览权限
         */
        if (this.isRole()) {
            this.list = this.roleService.get();
            System.out.println(this.getList());
            return "list";
        } else
            return ERROR;
    }
}
2.struts.xml配置action
           <action name="nuserAction_*" class="nuserAction" method="{1}">
                <interceptor-ref name="nuserInterceptorStack"></interceptor-ref>
                <result name="list">/user/ListUser.jsp</result>
                <result name="loginSuccess">main.jsp</result>
             </action>
             <action name="roleAction_*" class="roleAction" method="{1}">
                <result name="list">/role/ListRole.jsp</result>
             </action>
3.adduser.jsp中代码如下:
<s:form action="nuserAction_Add" method="post">
        <s:action name="roleAction_List" id="role"></s:action>
        <s:select list="#role.list" label="权限" name="nuser.role.id" headerKey="-1" headerValue="--请选择--" listKey="id" listValue="position"></s:select>
        <s:textfield name="nuser.name" label="用户名" value=""></s:textfield>
        <s:password name="nuser.password" label="密码" value=""></s:password>
        <s:submit value="提交"></s:submit>
        <s:reset value="重置"></s:reset>
   </s:form>
此处通过action标签 先执行roleAction_List 来获取 属性list值 然后赋给select标签的list属性 来生成下拉菜单。
有时候能够正常显示 但是有时又会报错 异常如下:
严重: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'nuser.role.id': The requested list key '#role.list' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
    at org.apache.struts2.components.Component.fieldError(Component.java:237)
不知道什么情况 请各位帮忙看看!
  • 写回答

2条回答 默认 最新

  • chenli348105874 2011-10-27 13:30
    关注

    #role.list
    你这个不是集合类

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择