Problem with Struts logic:iterate Tag


Web tier: servlets, JSP, Web frameworks: Problem with Struts logic:iterate Tag

  1. Problem with Struts logic:iterate Tag (1 messages)

    I am populating following simple List in action class and putting that in form class.
            private List getSystemTableList(ConfWizardBean confwizbean, HttpSession session){
                    ArrayList outerList = new ArrayList();
                    for (int i = 0; i < 2; i++)
                        ArrayList innerList = new ArrayList();
                        innerList.add(0,"Ist Column");
                        innerList.add(1,"2nd Column");
                        innerList.add(2,"3rd column");
                        innerList.add(3,"4th Column");
                    return outerList;

    relevant JSP code is as follows

      <%-- Iterate through the system list --%>
      <bean:define id="systemList" name="MyForm" property="systemTableList"/>
      <logic:present name="systemList">
      <logic:notEmpty name="systemList">
      <logic:iterate id="innerList" name="systemList" indexId="index">

      <logic:iterate id="1stCol" name="innerList" offset="0"/>
      <logic:iterate id="2ndCol" name="innerList" offset="1"/>
      <logic:iterate id="3rdCol" name="innerList" offset="2"/>
      <logic:iterate id="4thCol" name="innerList" offset="3"/>
       <TD align="center" class="bodyText" nowrap><bean:write name="1stCol" /></td>
       <TD align=center valign=middle><bean:write name="2ndCol"/></td>
       <TD align=center valign=middle><bean:write name="3rdCol" /></td>
       <TD align=center valign=middle><bean:write name="4thCol"/></td>

    I am trying to print the above list in Jsp page but it always print the value "4th Column" in all the four columns of HTML. Somehow it always uses the offset=3. What I am doing wrong here?.

    the output is as follows

     4thCol 4thCol 4thCol 4thCol
     4thCol 4thCol 4thCol 4thCol

    But the correct output should be as follows

     1stCol 2ndCol 3rdCol 4thCol
     1stCol 2ndCol 3rdCol 4thCol

  2. Use JSTL in preference to the Struts logic tags if you can. The following gives the correct result:

      <c:forEach items="${outerList}" var="outer">
          <c:forEach items="${outer}" var="inner">
            <td><c:out value="${inner}"/></td>