views:

34

answers:

1

I have an object with a method

  public boolean hasPermission(String role) {
   return permissions.contains(role);
  }

I want to do the equivalent of:

<c:if test="${row.hasPermission(role)}">
    <td></td>
</c:if>

But I cannot access the hasPermission method from within the JSP file. How can I do it?

+2  A: 

You can't, directly. You have two options:

Bozho
You can also declare getter (something like _getPermissions_) and use it from jstl: _row.permissions_
Nikita Rybak
How would I check that row.permissions contains a certain value?
Steve
Bozho
@Steve If _row.permissions_ returns Map, you can access it as any other map in jstl (_row.permissions[role]_ IIRC). Same with Set. (Not sure if you can pass parameter into getter directly, but may be worth a try too.)
Nikita Rybak
you're better off writing a custom jstl function - its very easy to write one, and you'd get rid of this iterate and compare business (which is definitely not a good idea) - see http://download.oracle.com/javaee/5/tutorial/doc/bnalg.html
Chii