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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL List Help" Watch "JSTL List Help" New topic
Author

JSTL List Help

Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
This is what the below code is printing out.

List(1) item (1)
List(2) item (1)
List(2) item (2)

List(1) item (2)
List(2) item (1)
List(2) item (2)

But I want it to print out like so:

List(1) item (1)
List(2) item (1)

List(1) item (2)
List(2) item (2)

I have tried many different ways to do this but just cant get it working properly. I would appreciate any help and/or direction.

Thanks in advance.


Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
Anyone have any idea? Please help if possible.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
I'm not entiresly certain about your data structure here. You seem to have nested for loops? Lists of Lists?

You would have to have a loop for the size of the list - do you presume that both lists are the same length? If they are parallel lists, why do you not have an object that has two attributes: impact and quality?


Cheers,
evnafets
[ September 07, 2005: Message edited by: Stefan Evans ]
Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
Hi thanks for answering! What I am dealing with are arraylists that contain maps for each instance. I have a form where an impact person will enter information and then a quality person will have to buy that impact off. It could stop at one map per list or it could grow depending on whether the impact was accepted or rejected.

I didnt post the entire code because it fairly long. And I am at home right now so I cant post it now. I will try your example tomorrow!

Thanks for you time,
Crystal
Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
Hi evnafets - Hope you are still around. I tried your example but couldnt get it to work. I am posting the entire code that I am trying to display so you may have a better understanding of what I am trying to do. I know it's long, tedious and ugly but I am at my wits end.

I would appreciate further direction if you have time. Thanks.

Crystal




[ September 08, 2005: Message edited by: Crystal Bazil ]
[ September 08, 2005: Message edited by: Crystal Bazil ]
Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
anyone?!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Please read this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
>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
Crystal Bazil
Ranch Hand

Joined: Sep 28, 2004
Posts: 38
Bear Bibeault - I apologize for being obtrusive. I just get too excited sometimes. It won't happen again.

Evnafets - I will give your advice a try. Thanks - will let you know how it goes!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

No need to apologize. Everyone would like to get their questions answered as soon as possible. But badgering the volunteers who answer questions at this site proves to be counter-productive.

The article I pointed you to (as well as the related articles) will help you make the most of this site.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL List Help