我有一个网页显示具有以下数据结构的值列表。
Class MyBean
private List<NewObj> newList;
getNewList();
setNewList(List);
Class NewObj
private String name;
private List<CustObj> custList;
getCustList();
setCustList(List);
Class CustObj
private String age;
我能够遍历列表并显示值。我在其间包含了隐藏标记,以便我可以从Form中获取Action类中的值。
JSP:
<s:iterator value="myBean.newList" status="matStat">
<s:hidden name="myBean.newList[%(#matStat.index)].name"></s:hidden>
<tr>
<td><s:property value="name" /></td>
</tr>
<s:iterator value="custList" status="reqStatus">
<s:hidden name="myBean.newList[%(#matStatus.index)].custList[%(#reqStatus.index)].requestId"> </s:hidden>
<tr>
<td><s:property value="age" /></td>
</tr>
</s:iterator>
</s:iterator>
当我尝试从我的action类访问值时,值为NULL,我的意思是对象myBean为NULL。
行动类:
myBean.getNewList()
我在上面一行获取NPE,因为myBean对象为空。仅供参考,我在动作类中同时拥有myBean的getter和setter。
来自浏览器的JSP来源:以下是我通过浏览查看页面来源
从浏览器中获取的内容摘录<input type="hidden" name="myBean.newList[%(#matStat.index)].name" value="" id="myForm_myBean_newList[%(#matStat.index)].name"/>
name的值实际应为 myBean.newList [0] .name
答案 0 :(得分:2)
感谢您的回复。
在对每个单词进行分析之后,我发现我使用的表达式是错误的。 我使用()而不是{}来访问struts迭代器中的列表索引。更正的JSP如下所示。现在,它的工作正常。
<s:iterator value="myBean.newList" status="matStat">
<s:hidden name="myBean.newList[%{#matStat.index}].name"></s:hidden>
<tr>
<td><s:property value="name" /></td>
</tr>
<s:iterator value="custList" status="reqStatus">
<s:hidden name="myBean.newList[%{#matStatus.index}].custList[%{#reqStatus.index}].requestId"> </s:hidden>
<tr>
<td><s:property value="age" /></td>
</tr>