java - html :options collection - No getter method available for property value

标签 java jsp struts

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

在我的 Action 类中 -

            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)字符串,如下所示: 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 中。 为什么?

最佳答案

用Strut的LabelValueBean包裹acct1acct2,像这样:-

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);

关于java - html :options collection - No getter method available for property value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972691/

相关文章:

java - Android中如何在一定时间后显示通知

java - 比 Jconsole 更好的查看 JMX bean 的选项

jsp - Struts 2 表单的动态 id 值

java - 无法在 JSP 内迭代列表

java - 使用 jsp 和 struts 1 自动聚焦 html 标签

java - 将 JPanel 绘制到 BufferedImage 或打印它而不先将其渲染到屏幕

java - 通过命令行执行程序

java - JSP - 如何获得以毫秒为单位不断更新的时间

java - 将 name 和 id 属性添加到 textarea (struts)

java - 身份验证成功后过滤器不转发页面