Blog Compass Lite 2.0 - personal blog About Me Album Bookmarks

Thursday, March 23, 2006

Passing dynamic offset value to struts logic:iterate tag

JSP: how to pass dynamic offset value to struts logic:iterate tag in a jsp page.

Problem Scenario:

Using <logic:iterate> tag in a JSP page, we need to pass a dynamic value for its length or offset, like this:

<bean:write name="element" property="value" offset="offsetValue" length="lengthValue"/>

where offsetValue and lengthValue are not pre-defined.


The real problem I encountered was the parsing error since both <% %> quote and struts tags are server-side. Using single quote for logic:iterate offset attribute and double quotes for request.getAttribute, as below:

<logic:iterate name="serverTypes" id="serverType" offset='<%=(String)request.getAttribute("offset")%>' >
     <bean:write name="serverType"/>