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

EL JSTL if test syntax

Mitch Young

Joined: Dec 15, 2006
Posts: 10
Hi All,
I an having problems comparing the string value of a bean property with another string passed into the jsp as a param using EL and a c:forEach loop.

I have an ArrayList of beans that holds menu items. I'm using a c:forEach to loop through all the beans in the array and only display the ones that have a category property value that matches the param value from the previous page.

<c:forEach var="cm" items="${cacheMenu}" > // ArrayList of MenuBeans

// I have tried all the following :
// cat is the category type like Pizza
<c:if test="${cm.category eq}">
<c:if test="${cm.category ==}">
<c:if test="${cm.category == 'Pizza'}">
<c:if test="${cm.category == '<%=cat%>'}">
<c:if test="${cm.category eq}">
<c:if test="${cm[category] eq}">
<c:if test="${cm['category'] eq}">
and even more...
<td >${cm.item} <input input="text" size="2" value=""/></td>
<td>${cm.price} <input type="hidden"/></td>

If I use <c:if test="${cm.category != null}.

It prints all the MenuBeans in the list so I know it's the syntax of the if test that's wrong.
Thanks much.">
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Have you definitively verified that cm.category and contain the exact same string including case and whitespace?

[Asking smart questions] [About Bear] [Books by Bear]
Mitch Young

Joined: Dec 15, 2006
Posts: 10
Thanks Bear,
That was it, whitespace (Duhh).
It is sorta covered in the JavaRanch Style Guide.
subject: EL JSTL if test syntax
It's not a secret anymore!