By default logic:iterate will increment the loop by 1. What do i need to do if i need to increment the loop by 2?

Ted Husted

Iterate is not a loop. It passes over the items in a collection. If you don't want to process all the items, don't put them in the collection to begin with =:0)

Though, you could do something with a scriptlet so that it would not handle some items.


<% int i = 0; %>
<logic:iterate id="lot" name="list" >
<% i++; if ( i % 2 == 0) { %>
<bean:write name="lot" property="name"/>
<% } else { %>
<!-- skipping alternate lot -->
<% } %>

In Struts 1.1, there is an indexId bean provided by iterate that you could test instead of rolling your own counter.

But this sort of thing is generally not recommended! Your Action should determine precisely what data the page needs and create the appropriate collection for the circumstances. The page should then just be able to render whatever it is given. If a page has to pick-and-choose anything, then the Action is not doing its job =:0)

Depending on your needs, you might also want to create a custom tag that applies whatever business logic you need. Struts provides a handy set of generic tags, but the idea behind JSP tags is that you can write whatever tags you need for your particular circumstances.

HTH, Ted

--
Ted Husted,
Struts in Action

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact