aspose file tools*
The moose likes JSP and the fly likes tag to loop a List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "tag to loop a List" Watch "tag to loop a List" New topic
Author

tag to loop a List

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I am looking for a tag to loop a List, which can take two items in each loop, coding will like this



Thanks.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You can use JSTL's forEach tag. But don't use var="item". Use the varStatus attribute instead, to access the list directly via the current loop index. I let you figure out how to write it.


[My Blog]
All roads lead to JavaRanch
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Christophe Verré wrote:You can use JSTL's forEach tag. But don't use var="item". Use the varStatus attribute instead, to access the list directly via the current loop index. I let you figure out how to write it.


is it like this ?



Thanks.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Why "2*" ? status.index will return you the proper index.

Also, you'll have to be careful that the list contains pairs. If the array ends with a single element, put your helmet on, this is going to blow.
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Christophe Verré wrote:Why "2*" ? status.index will return you the proper index.

I need to display a List into two columns in a table, each loop, I need to take two items and put into a <tr>.

Christophe Verré wrote:put your helmet on.

yes, I need this protection.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Then why do you not have 2 arrays, or an array whose elements are an array with 2 elements?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Bear Bibeault wrote:Then why do you not have 2 arrays, or an array whose elements are an array with 2 elements?


don't understand...



I am trying to get this output with forEach, what you will do , has another better way ?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Rather than skipping every other item, I'd make the structure represent the data better. A 2D array, if you will.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tag to loop a List