【问题标题】:html:options collection - No getter method available for property valuehtml:options 集合 - 没有可用于属性值的 getter 方法
【发布时间】:2011-02-11 18:31:49
【问题描述】:

我需要创建一个下拉菜单,我需要在其中显示来自数据库的 5 个帐号。我打算做的是,将这 5 个帐号设置为数组列表,然后该列表将保存在会话常量中。这个常量需要从我的 JSP 中获取。

在我的行动课上 -

            HttpSession session = request.getSession();

            ArrayList  accts = new ArrayList();
            String acct1 = data.getAccountId1();
            String acct2 = data.getAccountId2();
            accts.add(acct1);
            accts.add(acct2);
            session.setAttribute(
                    WorkConstants.TEST1,   
                    accts);

TEST1 被定义为公共字符串,如下所示: public String TEST1 = "Test1";

在我的jsp中我是这样编码的。

<td valign="top">
    1. accounts<span class="bodyCopy"><font color="#ff0000"> * </font></span>:
    <br/>
    <html:select name="MyDataForm" property="accountNumber" 
    styleClass="formContent">
        <html:options collection="<%= WorkConstants.TEST1 %>" 
        property="value" labelProperty="label" styleClass="formContent"/>
    </html:select>
    <br/>
</td>

但这不起作用。 出现错误 - 名称 Test1 下的 bean 的属性值没有可用的 getter 方法。看起来我的数组值没有设置到 TEST1 中。 为什么?

【问题讨论】:

    标签: java jsp struts


    【解决方案1】:

    用 Strut 的 LabelValueBean 包裹 acct1 和 acct2,如下所示:-

    ArrayList  accts = new ArrayList();
    
    String acct1 = data.getAccountId1();
    String acct2 = data.getAccountId2();
    
    accts.add(new LabelValueBean(acct1, acct1));
    accts.add(new LabelValueBean(acct2, acct2));
    
    session.setAttribute(WorkConstants.TEST1,accts);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 2014-03-02
      • 1970-01-01
      相关资源
      最近更新 更多