开发者

Expression language implicit objects

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 cou开发者_开发百科ld I do this?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜