File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes string comparison with EL / JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "string comparison with EL / JSTL" Watch "string comparison with EL / JSTL" New topic

string comparison with EL / JSTL

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I've just started trying to incorporate EL/JSTL into my coding, so bear with me, as I had trouble finding documentation on my problem. I have a List stored as a session attribute under the name "dates". For example:

I have a typical HTML select that dates is supposed to populate:

As you can see, when a date is chosen, the JavaScript submits the form and I handle it like this:

That already works. The only functionality I'm trying to add is to cause the option that was selected to be selected once the page comes back. I'm not sure how to do the String comparison between date and currentDate. Here's the message from the JasperException I get when I try to load the page:

When I try to change it to date.equals(currentDate) instead of date == currentDate, I get this message:

Thanks for any pointers...
[ August 11, 2005: Message edited by: Stephen Huey ]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
>Attribute test invalid for tag otherwise according to TLD
In other words, the <ctherwise> tag doesn't have an attribute called "test"
<ctherwise> is meant to be the catchall at the bottom of a series of <c:when> statements. Like the "default" option for a case statement, or the final "else" at the end of an "if ... else if ... else if ... else...

Solution: remove the test attribute from the otherwise clause.

Question: Why are you testing ${country.continent == 'Africa'} anyway?
If you need an extra test, you need a new <c:if> or <c:when> clause.
[ August 11, 2005: Message edited by: Stefan Evans ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63854

[Bear edit: removed answer that Stefan bet me to!]

P.S. When posting code, it's a good idea to check the 'disable smilies' checkbox.
[ August 11, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Ha...yeah, I noticed that country.continent == 'Africa' and fixed it and I was too sleepy to remember at that point that I had just posted that on JavaRanch, but it wasn't the cause of the initial problem because it was breaking before that. Now you can probably find online where I got my sample code from!

Anyway, the otherwise bit makes total sense...I think I was thrown off by thinking the error was caused by an entirely different part of the code. It was near the end of the work day, and I was *pretty* tired!

I agree. Here's the link:
subject: string comparison with EL / JSTL
It's not a secret anymore!