How can I maintain a SessionScoped
object between redirects?
I have a main page which accesses a Stateless
bean.
I also have a button which is doing a redirect (FacesContext.getCurrentInstance().getExternalContext().redirect("/to/my/sevlet");
) to a specific path, and by this invoking the webservlet.
The webservlet itself creates some contition-based response, but that should not matter at the moment.
The problem is: when I'm redirected to the servlet, I lose my session scoped bean property that was set during the initial access of the stateless bean..
How can I maintain a sessionscope between pages switch/redirect?
@Stateless
class myStateless {
@Inject
MySessionBean sessionBean;
private doSomething() {
sessionBean.setSessionProperty(true);
}
}
@SessionScoped
class MySessionBean {
Boolean sessionProperty = false;
}
@WebServlet
class MyWebServlet {
doGet(..) {
out.println("session property status is" + String.valueOf(sessionBean.isSessionProperty()); //always false
}
}