parametersstruts2ognl

How to pass parameters from textfields inside of <s:iterator> tag to the action in Struts 2?


I have a JSP with an <s:iterator> tag's 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 <s:iterator> tag's textfields, now I want to be able to pass the textfields values from <s:iterator> 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 getters are called fine when I navigate to the JSP, but when I submit a form from the JSP, I expectd the values that I put into the textfields inside <s:iterator> tag should pass and update the object in the action class, 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.