• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add new row in JSTL table

 
John Storta Jr.
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jpsx page and a bean that provides an Arraylist of calendar days.

The jspx page contains the following loop for displaying each of the days in a table. This is not the exact code, but a representation.


This works fine, but as would be expected, it just display everything in a single row. Not a very good looking calendar. I am trying to add code to move to a new row every 7 days.


I tried adding the following just before the </c:forEach> tag in order to end the current row and start a new one if the current day is Sunday. (Meaning the next day is Monday and I need to start a new week)


Since my tags are then misaligned, it is throwing off the xml parser. I could do this within a servlet instead, but I was hoping to avoid that.


Does anyone have any thoughts on how to insert a new table row in the middle of a JSTL forEach loop?

I am willing to change my data structure if there is something I am overlooking.


Thanks
 
Paul Clapham
Sheriff
Posts: 21881
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using XML then yeah, that approach isn't going to work.

I would do something in the model to build a data structure which matches what you want to see in the view, rather than having the view construct part of that data structure. That would be something like a list of weeks, where each week consists of a list of seven days.
 
John Storta Jr.
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I had considered that, but wanted to make sure I was not overlooking some feature that would solve all of my problems before I started reworking data structures.

Oh well.


Thanks for the input.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth would you be using jspx? Do you also poke yourself with sharp instruments?

jspx is intended as an intermediary format and for code that is auto-generated. It is not meant for hand-coding, and you end up running into endless problems like this. My advice is to ditch the jspx and write jsp as intended.
 
Paul Clapham
Sheriff
Posts: 21881
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there are any "features" which let you do this. The approach would be similar to what you'd do in XSLT or other functional languages:



So if your data structure allows you to extract weeks from your list and days from your week, you could do that. It might involve processing the list once for each week, for example.
 
John Storta Jr.
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya know Bear, I have often asked myself that same question. I originally moved to jspx when I was trying to use facelet templates. It seemed to only work if I had xml-compliant pages. I have since set aside facelets, but using jspx stuck. Part of me figured it was better.

And I will say it has caused me no end of difficulty as I seem to always run into something or other that is impossible or simply more difficult because of it.

Maybe time to rethink my choices.


Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!