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 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable