wood burning stoves*
The moose likes JSP and the fly likes JSTL/EL c:if inside of c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL/EL c:if inside of c:forEach" Watch "JSTL/EL c:if inside of c:forEach" New topic
Author

JSTL/EL c:if inside of c:forEach

Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
I have an ArrayList of beans. I set up my forEach like this...



And this works just fine. But now I only want to print the ones that have a ${order.orderType} = 'O'. So I thought I could do something like this...



WDSC says that I can't do tis. It tells me "Missing quotes for attribute value".(refering to test).

Also, is there a way to get the size of the ArrayList? I need to get a value from the last element in the ArrayList...is there an easy way to do that?

[BPSouther: Fixed broken code tag]
[ April 04, 2008: Message edited by: Ben Souther ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Originally posted by Bryce Martin:
WDSC says that I can't do tis. It tells me "Missing quotes for attribute value".(refering to test).
Looks ok to me on first inspection. What's WDSC? An IDE? If so, what happens when you run it outside of the IDE?

Also, is there a way to get the size of the ArrayList?
Check out the fn:length() JSTL function.

I need to get a value from the last element in the ArrayList...is there an easy way to do that?
If you have the index of the item, you can use the EL "array notation".
[ April 04, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
To use the array notation I would have to loop all the way through the ArrayList to capture the last index...I guess I could do that possibly...

Yes, WDSC is an IDE. Its IBM's development studio. WebSphere Development Studio. Its based on Eclipse. I'm not sure what it would do outside of the IDE. We run on WebSphere application servers, so it pretty much stands to bear that if the IDE says its not legal then the App server will throw a fit too. Sucks, but that is what we've got. I'm going to go keep picking away at it.

Thanks.
K.Suresh Kumar
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
Hi,
ArrayList have size() method.It is used to find the size of the ArrayList.

Regards,
Suresh Kumar.K
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Originally posted by K.Suresh Kumar:
ArrayList have size() method.It is used to find the size of the ArrayList.
But since it cannot be called using JSTL and EL, that's not useful.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Originally posted by Bryce Martin:
To use the array notation I would have to loop all the way through the ArrayList to capture the last index
No. That's why I mentioned <fn:length()>

I'm not sure what it would do outside of the IDE.
When something that looks like it should work doesn't in an IDE, the first order of business is running it "for real" outside of an IDE. If you don't know how to deploy and run a web app outside of the IDE, that's the next thing to do before you write another line of code.
K.Suresh Kumar
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
Hi,
Yes my previous post not helpful for you. But following one definitely helpful for you.

<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
Length of ArrayList is ${fn:length(<your arraylist scoped variable>)}

Regards,
Suresh Kumar.K
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL/EL c:if inside of c:forEach