开发者

JSF 2.0 how to display element depending of the user right?

开发者 https://www.devze.com 2023-03-12 00:17 出处:网络
I am writing an application using JSF 2.0, java ee and glassfish. My user interface is simple xhtml containing jsf.

I am writing an application using JSF 2.0, java ee and glassfish.

My user interface is simple xhtml containing jsf.

I want my user to login and depending their right have different element displayed on the same pages.

is it possible usi开发者_如何学JAVAng jaas ?

Thanks in advance loic


If you don't want to write framework type code to do this "behind the scenes" you could bind the rendered attribute of the component to a method which checks the user's access rights e.g.

public boolean isUserAllowedAccess() {
        return FacesContext.getCurrentInstance().getExternalContext().
           isUserInRole("ROLE_ADMIN");
         // or whatever authorization code you want
    }

and then refer to it in the 'rendered' attribute of your JSF-tags e.g.

rendered="#{authBean.userAllowedAccess}"

You can wrap multiple components using panels e.g.

<h:panelGroup rendered="#{authBean.userAllowedAccess}">
0

精彩评论

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