我需要创建一个下拉菜单,我需要在其中显示来自数据库的 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
包裹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);
关于java - html :options collection - No getter method available for property value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972691/