How to pass a Maplt;ObjectA, Listlt;ObjectBgt;gt; to action in Struts 2(如何传递一个Maplt;ObjectA,Listlt;ObjectBgt;gt;在 Struts 2 中执行)
问题描述
我有一个事件对象,里面有一个Map,ObjectA是标签,list<;ObjectB> 是表格行.使用以下代码,我可以正确显示表格,但是当我将表单提交到 Action 类时,地图在事件中是 null.
I have a event object, inside there is a Map<ObjectA, List<ObjectB>>, the ObjectA is the label, and the list<ObjectB> are table rows. With following code, I can display the tables correctly, but when I submit the form to Action class, the map is null inside the event.
JSP 代码:
<s:iterator value="event.planMap" var="map" >
<h4>Plan Type: <s:property value='key' /></h4>
<table id="plan">
<s:iterator value="value" status="stat" var="detail" >
<tr>
<td><input type="text" id="name" name="event.planMap['%{#map.key}'][%{#stat.index}].name" value="<s:property value='name'/>"/></td>
<td><input type="text" id="text" name="event.planMap['%{#map.key}'][%{#stat.index}].text" value="<s:property value='text'/>"/></td>
<td><input type="text" id="contact" name="event.planMap['%{#map.key}'][%{#stat.index}].contact" value="<s:property value='contact'/>"/></td>
</tr>
</s:iterator>
</table>
</s:iterator>
@Andrea &Roman,所以我修改了代码.显示表格是正确的,但我得到了错误,它进入了结果输入.如果我删除 planMap,则操作会成功.所以至少我知道错误是 planMap.修改后的代码是:
@Andrea & Roman, So I modified the code. displaying the table is correct, but I got error and it went to Result input. If I remove the planMap, the action goes to success. So at least I know the error are the planMap. The modified code is:
事件定义:
The Event definition:
public Event {
private Map<Object_A, Object_B> planMap;
public Map<Object_A, Object_B> getPlanMap {
return this.planMap;
}
public void setPlanMap(Map<Object_A, Object_B> planMap) {
this.planMap = planMap;
}
}
Object_B 定义:
The Object_B definition:
public Object_B {
private List<Object_C> details;
public List<Object_C> getDetials() {
return this.details;
}
public void setDetails(List<Object_C> details) {
this.details = details;
}
}
JSP代码为:
<s:iterator value="event.planMap" status="mStat" >
<h4>Plan Type: <s:property value='key' /></h4>
<table id="plan">
<s:iterator value="value.details" status="stat">
<tr>
<td><input type="text" id="name" name="event.planMap['% {#mStat.index}'].details[%{#stat.index}].name" value="<s:property value='name'/>"/></td>
<td><input type="text" id="text" name="event.planMap['%{#mStat.index}'].details[%{#stat.index}].text" value="<s:property value='text'/>"/></td>
<td><input type="text" id="contact" name="event.planMap['%{#mStat.index}'].details[%{#stat.index}].contact" value="<s:property value='contact'/>"/></td>
</tr>
</s:iterator>
</table>
</s:iterator>
推荐答案
我在以下更改后使其工作.
I made it work after the following change.
<s:iterator value="event.planMap" status="mStat" >
<h4>Plan Type: <s:property value='key' /></h4>
<table id="plan">
<s:iterator value="value.details" status="stat">
<tr>
<td><s:textfield id="name" name="event.planMap['%{key}'].details[%{#stat.index}].name" /></td>
<td><s:textfield id="text" name="event.planMap['%{key}'].details[%{#stat.index}].text" /></td>
<td><s:textfield id="contact" name="event.planMap['%{key}].details[%{#stat.index}].contact" /></td>
</tr>
</s:iterator>
这篇关于如何传递一个Map<ObjectA,List<ObjectB>>在 Struts 2 中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何传递一个Map<ObjectA,List<ObjectB>>在 Struts 2 中执行
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
