posted 18 years ago
>I tried your example but couldnt get it to work
What about it didn't work? Did it give you an error message?
"It doesn't work" doesn't really convey much information.
What server and version are you using? What version of JSTL are you using? 1.0 or 1.1?
The code provided did use a JSTL1.1 feature that would only work on a JSP2.0 container (eg Tomcat5)
You're right this is complicated. Probably much more so than it needs to be.
A List of Maps of Lists?
And then you do a if count == 1, count==2 to distinguish the items in the list? Why bother looping?
There is also a lot of IMO needless if/else checking for very minor differences in code. It would be better to put values in dynamically.
Your nested loops reuse the same variable for status indicator. varStatus="status" That would be bad.
(end rant on code)
Ok, these are my assumptions, please correct me if I am wrong.
1 You have two "parallel" Lists.
The items in the Lists are Maps.
Each value in a map is an ordered list of attributes
Impact = items 1-6 (in order): impactClass, impactAffect, comments, recommendation, email, date.
Quality = items 1-4 (in order): Findings, Comments, reviewedby, date
2 - You want to print
impactList[1]
qualityList[1]
impactList[2]
qualityList[2]
...
3 - impactList and qualityList are both the same size - ie for each impact entry there is a quality entry.
4 - This page is read only - you want the fields disabled/readonly.
I would suggest you start a page from scratch. Get the ordering correct, and then and copy/paste sections in as necessary.
Your initial problem is caused by nested loops. You only want one loop accessing both lists. The easiest way to do that is to set up a loot with a counter, and then get each individual element of a list by its index. Thats what the code provided above did.
In my opinion you don't need that third nested list.
You can access list elements by index using square brackets notation.
So rather than
<c:forEach var="impactValue" items="${impactKeys.value}" varStatus="s">
<c:choose>
<c:when test="${(s.count == 1)}">
...
</c:when>
<c:when test="${(s.count == 2)}">
...
</c:when>
...
</c:choose>
</c:forEach>
You could do it like this:
<c:set var="impactValue" value="${impactKeys.value[1]}"/>
// stuff for first list value
<c:set var="impactValue" value="${impactKeys.value[2]}"/>
// stuff for second value
There is no need for a loop - you have code for each individual case anyway!
There is also probably a better way of doing those radio buttons than coding each individual case, but that should be enough to get you going for now.
Hope this helps.
evnafets