• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Complex Table and JSTL

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you considered nested List <UL><LI>... objects?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic