Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

problem incrementing loop in jstl  RSS feed

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you even need the inner loop?
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!