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

problem incrementing loop in jstl

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
I am trying to loop and create a table that is 4 columns and "X' amount of rows.

I did a test to loop 40 "lets say products", this should give me 10 rows of 4 columns, but it is giving me 40 rows of 4 columns

i am having trouble incrementing the outer loop as the inner loop loops i need to increment the value of the outer loop also to only loop through the 40 products and end up with 10 rows 4 cols.

Below is my test code

tia
John


[ September 11, 2008: Message edited by: John Schretz ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

If you want the outer loop to iterate 10 times, why are you telling it to iterate 40 times?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
i am really new to jstl
this is what i ultimatly want to accomplish

i want to get "X" number of products from the DB then create a table that is 4 columns and X amount of rows


[ September 11, 2008: Message edited by: John Schretz ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Originally posted by John Schretz:
this is what i ultimatly want to accomplish
What is "this"? It's not going to be inferred by looking at code.

If what you are trying to do is to iterate over 40 items in order to put them into a 4 column table, do the math to figure out how many rows you need. Fiddling with the counter is unlikely to get you anywhere, and will just likely have bizarre side effects.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

OK, I caught your ninja edit:
i want to get "X" number of products from the DB then create a table that is 4 columns and X amount of rows

That doesn't seem to match what you said earlier.

But if it is what you are trying to accomplish, what's the issue? Just iterate over the list of products.
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
i was trying to simulate having 40 products

i was trying to keep incrementing i in the inner loop so whe the loop goes back to the outer loop i has the proper index in the array so to speak

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

You shouldn't be screwing with the counter, and for the life of me I still can't figure out why you are trying to.

The whole point of the tag is that it will handle all that for you -- just give it the collection to iterate over.
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
ok, so i put the collection in the second loop. as per comments in code how do i tell it to only loop 4 times

I think i am having mostly syntax issues here. I am a core java programmer trying to teach myself j2ee ect.

I could figure this out in core java no problem.



thanks
john



[ September 11, 2008: Message edited by: John Schretz ]

[ September 11, 2008: Message edited by: John Schretz ]

[ September 11, 2008: Message edited by: John Schretz ]
[ September 11, 2008: Message edited by: John Schretz ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Why do you even need the inner loop?
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
dont i need it to construct the table to go to the next row?




[ September 11, 2008: Message edited by: John Schretz ]
[ September 11, 2008: Message edited by: John Schretz ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem incrementing loop in jstl