• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

EL JSTL if test syntax

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.">
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,
That was it, whitespace (Duhh).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic