For loop issue in Struts2

I found below code in JSP at somewhere.

  <%
    int cnt =1;
    for(int i=1;i<=iTotalweeks;i++)
    {
    %>
    <tr>
      <% 
        for(int j=1;j<=7;j++)
        {
            if(cnt<weekStartDay || (cnt-weekStartDay+1)>days)
            {
             %>
            <td align="center" height="35">&nbsp;</td>
           <% 
            }
            else
            {
             %>
            <td align="center" height="35" id="day_<%=(cnt-weekStartDay+1)%>"><span><%=(cnt-weekStartDay+1)%></span></td>
           <% 
            }
            cnt++;
          }
        %>
    </tr>
    <% 
    }
    %>

Now I’m doing same in struts2. But I’m struct in the middle of coding. How to compare current JSP variable (cnt) with action class’s variable.

 <%
    int cnt =1;
 %>

 <s:iterator begin="1" end="%{iTotalweeks}">
    <tr>
        <s:iterator begin="1" end="7">

            <s:if test='%{cnt<weekStartDay || (cnt-weekStartDay+1)>days}'>
            <%
            {
             %>
            <td align="center" height="35">&nbsp;</td>
           <% 
            }
            else
            {
             %>
            <td align="center" height="35" id="day_<%=(cnt-weekStartDay+1)%>"><span><%=(cnt-weekStartDay+1)%></span></td>
           <% 
            }
            cnt++;
          %>
          </s:iterator>
    </tr>
    </s:iterator>

In the above code weekStartDay, days and iTotalweeks are variables in action class and cnt is a variable in current JSP.

 public int getDays() {
    return days;
}

public int getWeekStartDay() {
    return weekStartDay;
}

public int getITotalweeks() {
    return iTotalweeks;
}


Source: jsp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.