Match a list using a JSP page and get the values ​​in the Action class. It gives a list of results as a Cartesian product in the Action class.

I am working on a project where I need to send data from a JSP page to an action class in a form List, I install List<Object>from an action class the first time I map to a JSP page, when I perform an action to save details. In action, I get the values List<Object>as a Cartesian product for each value.

eg. If there is a list of 3 objects (with 4 members) passing in the JSP, when it returns to action, it generates 12 objects with different JSP values.

The image shows a demo user interface, this is not a table, but each row represents a list object

The image shows the Demo UI which I need
in an action class

 List<Pojo> PojoList = new ArrayList<Pojo>();

Can someone suggest me which approach I should use, this is a new scenario for me, I also tried some example from the Internet, but could not, I also iterate over the list in JSP, but it gave me an error. (not quite an error but it does not give fields on the JSP);

In JSP:

<c:forEach var="pojo" items="${pojoList}">
    <s:textarea name="pojo.field1">
    <s:textarea name="pojo.field2">
    <s:textarea name="pojo.field3">
    <s:textarea name="pojo.field4">
</c:forEach>

Return In Action class method (it outputs 12 objects)

try {
    System.out.println("List : "+pojoList);
    for (Iterator<Pojo> iterator = pojoList.iterator(); iterator.hasNext();) {
        Pojo pojo = (Pojo) iterator.next();
        System.out.println("\n MB : "+pojo);
       }
} catch (Exception e) {
    e.printStackTrace();
}

Please suggest me what will be wrong.

+4
source share
1 answer

If you have 3 fields in the list, each of them has 4 default fields added, so 3 * 4 = 12. The code works fine, but if you change it like

<s:iterator value="pojoList" status="stat">
    <s:textarea name="pojoList[%{#stat.index}].field1">
    <s:textarea name="pojoList[%{#stat.index}].field2">
    <s:textarea name="pojoList[%{#stat.index}].field3">
    <s:textarea name="pojoList[%{#stat.index}].field4">
</s:iterator>

it will use the same index for each field, so 3 pojos will be created / updated.

+1
source

All Articles