我有一个事件对象,里面有个Map<ObjectA, List<ObjectB>>,ObjectA标签和list<ObjectB>表行。使用以下代码,我可以正确显示表,但是当我将表单提交给Action类时,地图就null在事件内部。
Map<ObjectA, List<ObjectB>>
ObjectA
list<ObjectB>
Action
null
<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。修改后的代码是:
planMap
Event
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
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; } }
<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>
在进行以下更改后,我使其开始工作。
<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>