0

I use CDI to annotate beans. One bean called SessionManager holds the logined user information with the declaration:

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import javax.ejb.Stateful;

@Stateful
@Named
@SessionScoped
public class SessionManagerImpl implements SessionManager, Serializable {
    ...
    public UserDto getLoginedUser() {
        ...
    }
}

And the other is called DashboardController as:

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;

@Named
@RequestScoped
public class DashboardController implements Serializable {

    @Inject
    private SessionManager sessionManager;
    ...
    public void loadUserInfo() {
        ...
        UserDto userDto = sessionManager.getLoginedUser();
    }
}

The first time i open a page refer DashboardController, it works well. And if i continue to use the website, it still works. But if i don't click any page for some minutes, and come back to open the page, it will display a null pointer for the javassist$$getLoginedUser method invocation (sessionManager is not null when i use debug to watch). The session is still valid for i can get values from session map directly using faces context.

What's wrong with the SessionManager? Thanks.

xi.lin
  • 3,326
  • 2
  • 31
  • 57
  • 1
    I believe you're mixing some basic concepts, resulting in disaster. I suggest to carefully read the following answers to get the one and other straight: http://stackoverflow.com/a/13012973 and http://stackoverflow.com/a/8889612/ – BalusC Aug 28 '13 at 00:40
  • @BalusC Thank you for your explain! I did mixing the stateful session with web session. – xi.lin Aug 28 '13 at 15:21

1 Answers1

1

This occurs because your Stateful Session Bean (EJB) has passivated, and is not reintroduced to your session. If there isn't a strong need to make your session scoped object a session bean, I would just make it a SessionScoped managed bean.

John Ament
  • 11,595
  • 1
  • 36
  • 45