This question is related to the previous one in writing the session timeout handler .
The response in this thread included access to managed beans using a servlet. The recommendation (as seen here ) is to do this in a filter:
HttpSession session = request.getSession(false); User user = (session != null) ? (User) session.getAttribute("user") : null;
Presumably this selects a user class bean session. The problem is that this does not work.
It is not good that beans are in the session attributes, but they are wrapped in Weld. I wrote the doFilter () method as follows:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String sp = req.getServletPath(); System.out.println("------------------------"); System.out.println("doFilter(): " + sp); if (!sp.startsWith("/javax")) {
When this unloads the session attributes, I usually get something like this:
INFO: ------------------------ INFO: doFilter(): /Display.xhtml INFO: Attribute 1: org.jboss.weld.context.http.HttpSessionContext
Attribute # 2 seems to represent the bean I want. Needless to say, calling session.getAttribute ("login") does not work.
Can anyone tell me how to access a basic managed bean? I would prefer to do it in a way that was not tied to Weld, but that might not be possible.
jsf-2 servlet-filters cdi
Alanobject
source share