jsp - How to pass a Map<ObjectA, List<ObjectB>> to action in Struts 2 -


i have event object, inside there map<objecta, list<objectb>>, objecta label, , list<objectb> table rows. following code, can display tables correctly, when submit form action class, map null inside event.

jsp code:

<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, modified code. displaying table correct, got error , went result input. if remove planmap, action goes success. @ least know error planmap. 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;     } } 

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

the jsp code is:

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

the struts can access indexed properties of action bean, such list, map, etc., it's required element class should java bean map<objecta, objectc>, objectc wraps list<objectb>.

then use struts type conversion populate indexed property in answer how updated list values jsp in action.

indexing collection property of collection

it possible obtain unique element of collection passing value of given property of element. default, property of element of collection determined in class-conversion.properties using keyproperty_xxx=yyy, xxx property of bean class returns collection , yyy property of collection element want index on.

for example, see following 2 classes:

myaction.java

/**  * @return collection of foo objects  */ public collection getfoocollection() {     return foo; } 

foo.java

/**  * @return unique identifier  */ public long getid() {     return id; } 


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -