0

I am developing a Web/EE project, using GlassFish 4 as an Application Server.

I have a SessionScoped ManagedBean called UserStateBean and a AdminDirNotAdminDeniedFilter that acts as the 2nd filter of the filter chain, and checks if the logged in user per question is an admin.

The code of the Filter, in which I get access to the ManagedBean is this:

HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpSession session = request.getSession(false);
UserStateBean userState = (UserStateBean) session.getAttribute("userStateBean");

And after that I am calling the isAdmin() function on the userState instance: if (!userState.isAdmin()) and that's where I am getting the NoSuchMethodError.

I have verified that the userState instance is not null and that contains the correct username and password using the debugger.

This is an extract from the server.log of GlassFish.

And this is the UserStateBean.

Chris
  • 3,619
  • 8
  • 44
  • 64

1 Answers1

1

I don't know what is or was wrong with your bean because when I tried to reproduce it the userStateBean was always null.

But I would suggest that you let CDI manage your bean injection, that's easier and also less coding.

You yust have to change your @SessionScoped import of your managed bean from:

import javax.faces.bean.SessionScoped;

to:

import javax.enterprise.context.SessionScoped;

Then you can inject your bean into the filter like this:

@Inject
private UserStateBean userStateBean;

Maybe this can also help you with your new problem :)

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • The new problem was I didn't have getters/setters for the Managed Bean property, now it's all good. The thing is that I want to stick to Managed Bean properties, as they don't need a full application server to run (which is what I need for this project's scope). But I'll keep in mind the `CDI`, so thank you for your suggestion! // Also, the actual solution was weirdly a restart of GlassFish. – Chris Sep 01 '14 at 12:58