Search code examples
javajspparametersstruts2ognl

How to pass JSP iterator list to action in Struts 2


I have a JSP with an iterator list that iterates over an object created in the action with getters/setters.

I'm able to pull the mapped value from the action to the JSP iterator, now I want to be able to pass the JSP iterator list back to the action class to map the object but, I realized that it does not call my setter method.

Here is my JSP:

<s:iterator  status="stat" value="parameterList" >
    <tr id="<s:property value="#stat.index"/>">
        <td><s:textfield id="parameterList[%{#stat.index}].queryParameter" name="parameterList[%{#stat.index}].queryParameter"  cssClass="size30" labelposition="left"  ></s:textfield> </td>
        <td><s:textfield id="parameterList[%{#stat.index}].parameterValue" name="parameterList[%{#stat.index}].parameterValue"  cssClass="size30" labelposition="left"  ></s:textfield> </td>
    </tr>
</s:iterator>

and this is a snippet of the action:

private List<QueryParameter> parameterList = new ArrayList<QueryParameter>();

public void setParameterList(List<QueryParameter> parameterList) {
    this.parameterList = parameterList;
}

public DQA getDqaObject() {
    return dqa;
}

The getter gets called fine when I navigate to the JSP, but when I submit from the JSP, I am expecting the value that I put into the text field iterator should call and update the object in the action file, but the setter is not being called.


Solution

  • I resolved the issue, the problem was that in my getter(Which I forgot to post in the question) there were some logic that was preventing the getter to proceed to actually call the objects setter to set the parameter.