Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL JSTL if test syntax

 
Mitch Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you definitively verified that cm.category and param.cat contain the exact same string including case and whitespace?
 
Mitch Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,
That was it, whitespace (Duhh).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic