Skip to content
Advertisement

nested Java collection to list items per person per day in a calendar grid using JSTL?

I am developing an employee scheduler Java web applicatyion where an employee can specify days they will be out of the office for things such as vacation, business travel, etc…I have a simple mechanism for adding/editing/deleting these records. But I am struggling with the JSTL and which collector I should be passing to the jsp for the forEach looping.

Ultimately I need to display a table on a jsp page that looks omething like this:

JavaScript

Where [E] would be a list of items or events against that employee for that particular day

And this is a sample list of events from a sql call:

JavaScript

My first approach was to use nested hashmaps and key it with the day but I had difficulty reference the value in the map using JSTL because of the issues with using numbers for keys (My key was the cell number offset by the start day, October starts on day 5 or Friday).

EL access a map value by Integer key

JSTL and hashmap not working.

I foresee me making a bunch of loops in the servlet that populates some type of container to accomplish this.

I’m looking for at least something like “Oh, nest a List in a Map and stuff that in another map” to get me started.

Advertisement

Answer

Ok, I finally figured out the nested collection and loop myself, so I’ll answer my own question. Both the servlet and view code probably could use some improving, but it works.

Servlet:

JavaScript

View (not all Attributes used in the view are shown in the servlet):

JavaScript

Example output from the view

Sample Output

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement