1

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>

Community
  • 1
  • 1
Joyeeta
  • 11
  • 3
  • did you populate a jsp? – Roman C May 06 '14 at 05:42
  • Please, show us 1) your struts.xml (or annotation mapping if using convention plugin), 2) the destination action 3) the full jsp form including the submit button. +1 btw, nice question showing efforts. Oh, and be sure ObjB has a default constructor. – Andrea Ligios May 06 '14 at 08:49
  • The action methods are getting called fine. Also the data is dispalyed on the UI fine. The only issue is when I submit the form I do not get the value in the Map, hence not attaching the struts xml mapping.. The map is giving null value. I edited the code and added it again. Please let me know if anything else I need to add. Thanks for your help. – Joyeeta May 06 '14 at 17:08

1 Answers1

0

The fact that your values are displayed correctly means nothing, because even if a value attribute is right, the name attribute will be used to send the item and they're unrelated.

BTW now (after your edit) it's clear what the problem is: you are using two private inner classes.

Please, use a public class for both ObjA and ObjB, and it will work.

EDIT:

The only issue is when I submit the form I do not get the value in the Map, hence not attaching the struts xml mapping..

Since you are not attaching struts mapping, I can't see if your interceptor stack is nicely configured for this action. Then do it yourself, ensure you have the Default Interceptor Stack, or at least that the ParametersInterceptor is there. Remember that if you add an interceptor of your own, you need to add a stack too, otherwise you will be using a single Interceptor instead of adding it to the others.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243