I followed the below link: My issue is also similar but not able to troubleshoot it. Struts2: Updating the values of a "List Of Objects" inside a Map
I have a map of Integer
and ObjA
, a custom object which consists of only List<ObjB>
.
private Map<Integer, ObjA> displayMap = new HashMap<Integer, ObjA>();
ObjB
contain parameters like size, status etc.
JAVA code I am populating the displayMap
with all the object values and displaying it on the jsp. But when I submit the form again then the displayMap
becomes null.
public String displayColumn() throws Exception {
for (int i = 0; i < numberOfDoors.length; i++) {
int k = 1;
List<ObjB> objBList = new ArrayList<ObjB>();
while (k <= numberOfDoors[i]) {
ObjB objB =new ObjB();
objB.setSizeCd("1");
objBList.add(objB);
doorNoCounter = doorNoCounter + 1;
k++;
}
ObjA objA = new ObjA();
objA.setObjBList(objBList);
displayMap.put(i+1, objA);
}
return SUCCESS;
}
}
private class ObjA{
private List<ObjB> objBList;
public List<ObjB> getObjBList() {
return objBList;
}
public void setObjBList(List<ObjB> objBList) {
this.objBList= objBList;
}
}
private class objB{
protected String sizeCd;
public String getSizeCd() {
return sizeCd;
}
public void setSizeCd(String sizeCd) {
this.sizeCd = sizeCd;
}
}
JSP Code snippet:
<table class="tableStyle">
<tr>
<s:iterator status="outerStat" value="displayMap" var="parentMap">
<tr>
<s:iterator status="innerStat" value="%{#parentMap.value.objBList}" var="listLocker">
<td class="labelStaticText">Select Size Code:</td>
<td >
<s:textfield name="displayMap['%{#parentMap.key}'].objBList[%{#innerStat.index}].sizeCd" value="%{sizeCd}"/>
</td>
</s:iterator>
</tr>
</s:iterator>
</tr>