programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Devaka Cooray
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Knute Snortum
• Junilu Lacar
• paul wheaton
Saloon Keepers:
• Ganesh Patekar
• Frits Walraven
• Tim Moores
• Ron McLeod
• Carey Brown
Bartenders:
• Stephan van Hulst
• salvin francis
• Tim Holloway

problem incrementing loop in jstl

Ranch Hand
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 ]

Marshal
Posts: 67164
169
If you want the outer loop to iterate 10 times, why are you telling it to iterate 40 times?

John Schretz
Ranch Hand
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
Marshal
Posts: 67164
169

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
Marshal
Posts: 67164
169
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
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
Marshal
Posts: 67164
169
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
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
Marshal
Posts: 67164
169
Why do you even need the inner loop?

John Schretz
Ranch Hand
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 ]

 It is sorta covered in the JavaRanch Style Guide.