tags:

views:

48

answers:

1

I have a List variable called services in my JSP page. I need to add some markup to the page if there's more than 1 element in the list.

What I'd like to do is...

<c:if test="${services.size() gt 1}">
  <!-- markup... -->
</c:if>

But you can't invoke methods on Java objects in EL (I think this is perhaps the 364823782 time I've regretted that fact). You can only access getters on Java objects by dropping the 'get,' e.g. ${user.name} for a User class that has a getName() method.

What's the right way to evaluate this test?

+6  A: 

You are looking for fn:length(services). Remember to define the fn namespace.

http://download.oracle.com/javaee/5/tutorial/doc/bnalg.html

Thorbjørn Ravn Andersen
It's the right answer, but it's not the sort of answer I was really hopping for. What a pain. Why can't we have Groovy or Rhino instead of EL...
Drew Wills
That is just the way it is with JSP. I can strongly recommend upgrading to JSF and facelets.
Thorbjørn Ravn Andersen