aspose file tools*
The moose likes JSP and the fly likes Complex Table and JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Complex Table and JSTL" Watch "Complex Table and JSTL" New topic
Author

Complex Table and JSTL

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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.


GenRocket - A Test Data Generation Platform
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Have you considered nested List <UL><LI>... objects?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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

Joined: Jul 11, 2001
Posts: 15286
    
    6

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jul 11, 2001
Posts: 15286
    
    6

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

Joined: Dec 11, 2004
Posts: 13410

This one is a little uglier but it will allow you to create a simple HTML table:

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jul 11, 2001
Posts: 15286
    
    6

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

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Oct 13, 2006
Posts: 22
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


Go is to the fountain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complex Table and JSTL
 
Similar Threads
How to use multiple forEach Loops in EL?
Pagination using display tag and JSTL.Display problem
EL algorithm help
[ANNOUNCE] JSP Standard Tag Library (JSTL)
how to iterate list in a table using jstl