tags:

views:

1388

answers:

1

Accessing non-properties via jsp el

In the code below, I need to access a method that is not a property. I need a c:foreach variable to be visible to be the test as well. I'm dealing with someone else's code. I'm not particularly happy with the design of it, but that's easy when dealing with someone else's code.

I would prefer to just set the actual visible roles in the controller, but all of the data is read from a global cache in multiple places. The junk below represents the fewest lines of code to get desired behavior.

<c:forEach var="role" items="${resource.value.rs}">

//don't have access to role in scriptlet context

<c:if test="<% role.isVisible(session.getAttribute("authUser")) %>">

</c:if> </c:foreach>

A simple solution would be .. if I could do:

//can't call isVisible through el I don't believe

<c:if test="${role.isVisible(session.authUser)}">

but I am pretty sure you can't do that.

I'm in the process of rewriting to avoid scriptlets, but if anyone had a quick fix, I would entertain it.

Thanks.

A: 

I would prefer to just set the actual visible roles in the controller, but all of the data is read from a global cache in multiple places

Shouldn't be a problem if i understood it correctly.

I'm assuming the authUser is in the session scope

session.authUser

If not then set it:

<c:set var"authUser" value="${session.authUser}" scope="session" />

All you'd do then is find a way of feeding authUser from the session into the role Bean allowing you to:

<c:if test="${role.isVisible}">

aah maybe not..

I think I'd write a custom tag

<mytag:isVisible role="${role}" user="${session.authUser}">
    // do work
</mytag:isVisible>
raq