tags:

views:

45

answers:

2

I have a need to perform a bitwise test within a JSP but can't for the life of me figure out how to do it with EL.

I want to do something like:

<c:if test="${(test & testFor) == testFor}">
  <h3>Test Passed</h3>
</c:if>

Of course I can do it with ordinary JSP syntax:

<% if ((test & testFor) == testFor) { %>
  <h3>Test Passed</h3>
<% } %>
+2  A: 

JSP EL doesn't support bitwise operators (only arithmetic, logical and relational operators). If you want to do that, you'll need to encapsulate the operations within a java class, and expose that to the JSP. Alternatively, I believe you can write a custom function, that would look similar to those in the fn: JSTL namespace, but I'm not sure how to go about that.

skaffman
Thanks heaps, much appreciative, both your and Bozho's answers were very similar, but I had to choose one :)
Brett Ryan
+2  A: 

I think bitwise operators are not implemented in JSTL (see here)

You can implement a JSTL function, called bitwiseAnd(int, int) and perform the bitwise test in Java code

Bozho
Thanks heaps, much appreciative.
Brett Ryan