• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complex Table and JSTL

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Model that contains a Collection of Characteristic Groups. Each Characteristic Group contains a Collection of Characteristics. I need to construct a table that looks something like this:



and so on and so on. I'm having a hard time coming up with the jstl logic to handle this. My first attempt went something like this:



Obviously, that didn't work out well. I didn't have the row breaks where I needed them and several characteristic group were on the same row instead of seperate rows. Any tips as to a good solution for this would be much appreciated. Should I not be using a table?

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered nested List <UL><LI>... objects?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding some opening and closing TR elements seems to fix some of the issues. My code now looks like:



I'll keep plugging away.
[ January 10, 2007: Message edited by: Gregg Bolinger ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Have you considered nested List <UL><LI>... objects?


Yea, I thought about that. What would be the best way to get the indenting I need for the columns on the nested elements?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm
I wasn't thinking about lining up the columns.
Maybe tables would make more sense.

Is is always the same number of columns?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Hmm
I wasn't thinking about lining up the columns.
Maybe tables would make more sense.

Is is always the same number of columns?


Yes, it's always the same number of columns. I kind of like the UL LI idea. Been playing around with it. Problem is getting the LI widths to work right. If I text-alright: right, then the bullets don't line up.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This one is a little uglier but it will allow you to create a simple HTML table:

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, if it were my issue, I'd flatten the table out in the Java code and just pass a list of row beans to the JSP page.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
I think, if it were my issue, I'd flatten the table out in the Java code and just pass a list of row beans to the JSP page.


Darn good suggestion. Thanks Ben.
 
Stefan Evans
Bartender
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do it in JSTL by storing the "last" entry printed for each of the repeating fields, and only print it out if it changes..

Just for fun...

 
Joel Jorgensen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The c:forEach tag also allows you to track the status of the loop if you use the "varStatus" attribute (e.g. varStatus="charGroupStatus"). You can then use c:if tags to check whether the index is 0 (i.e. whether it is the first time through the loop) and print out the cells accordingly.

Like so:

This might not be the most efficient way to do it (because it does the two if checks for every single modelChar), but it seems readable and doesn't involve slightly unsual </tr> <tr> pairs (which the other solution that I thought of would require ;) ) and as long as you don't have thousands upon thousands of modelChars you can probably get away with it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic