permaculture playing cards*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "EL JSTL if test syntax" Watch "EL JSTL if test syntax" New topic
Author

EL JSTL if test syntax

Mitch Young
Greenhorn

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 param.cat}">
<c:if test="${cm.category == param.cat}">
<c:if test="${cm.category == 'Pizza'}">
<c:if test="${cm.category == '<%=cat%>'}">
<c:if test="${cm.category eq param.cat}">
<c:if test="${cm[category] eq param.cat}">
<c:if test="${cm['category'] eq param.cat}">
and even more...
<tr>
<td>${cm.category}</td>
<td >${cm.item} <input input="text" size="2" value=""/></td>
<td>${cm.description}</td>
<td>${cm.size}</td>
<td>${cm.price} <input type="hidden"/></td>
</tr>
</c:if>
</c:forEach>

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
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mitch Young
Greenhorn

Joined: Dec 15, 2006
Posts: 10
Thanks Bear,
That was it, whitespace (Duhh).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL JSTL if test syntax