tags:

views:

19

answers:

1

How can the JSF implicit objects be access via expression language?

For example, if I wanted to determine what roles the current principal is associated with, how could I do this?

A: 

If you're using JSF on JSP, then you can do it just the same way as you would do in "plain JSP EL".

#{pageContext.request}

If you're using JSF on Facelets, then you can omit the pageContext part from the way as you would do in "plain JSP EL".

#{request}

Either way, it returns the HttpServletRequest object.

However, the only method which determines the user role is the isUserInRole(String role) method. You can't pass arguments to methods in standard EL. You can however do that when you replace standard EL by JBoss EL.

#{request.isUserInRole(role)}

To install JBoss EL, just put jboss-el.jar in /WEB-INF/lib and add the following to the web.xml, assuming that you're using Mojarra:

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>
BalusC
BalusC, thanks for the help. I've just upgraded to Tomcat 7, which has updated support for EL. I'm going to give this a go and see if it works.
Wilson