0

I am trying to restrict certain pages in my web application to certain users, such as an administrator. However, I keep getting the following error:

Error Parsing: #{userSession.hasRole('ADMIN')}

I have tried several things but keep hitting a brick wall and was hoping someone may be able to shed some light.

My UserSession class has the following method:

public boolean hasRole(Role role)
{
    return roles.contains(role);
}    

I am also using the following Bean and session scope:

@ManagedBean(name="userSession")
@SessionScoped

Then, in my view, I am using:

<p:tab rendered="#{userSession.hasRole('ADMIN')}" title="Admin">

My Role class:

public class Role {

    public enum RoleType {
        ADMIN, USER
    }

    private RoleType type;

    public setRoleType(RoleType type)
    {
        this.type = type;
    }

    public RoleType getRoleType(RoleType type)
    {
        return this.type;
    }
}

As I am using a VM it's difficult for me to copy and paste my code onto here, but here are some screenshots of the stack trace:

https://i.stack.imgur.com/Slfh3.jpg

Any help is greatly appreciated.

James
  • 1,471
  • 3
  • 23
  • 52
  • In case of exceptions, it's helpful to include the full message and stack trace as that part basically represents the answer. We can just translate that in layman's terms. – BalusC Jun 08 '16 at 17:50
  • @BalusC I've added some screenshots of the stack trace. – James Jun 09 '16 at 08:09
  • That's helpful. See the duplicate for the answer. In the future, you'd better include the stacktrace as plain text instead of as an image. That improves searchability as they are usually used as search keywords in order to find answers (you should do the same yourself; just copypaste the exception type+message and canonicalized 1st line in a decent search engine). – BalusC Jun 09 '16 at 08:13
  • @BalusC thanks, I'll take a read now. Like I mentioned, I can't copy and paste the stack trace because of the VM I'm using. – James Jun 09 '16 at 08:17

0 Answers0