• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL List Help

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone have any idea? Please help if possible.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anyone?!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic