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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器