How do I retrieve the FacesContext within a Filter

前端 未结 1 348
太阳男子
太阳男子 2020-12-02 00:01

How do I retrieve the FacesContext within a Filter?

I followed following article on how to retrieve the FacesContext in a Filter:

h

相关标签:
1条回答
  • 2020-12-02 00:15

    How do I retrieve the FacesContext within a Filter?

    You cannot. The FacesContext is created by the FacesServlet and thus only available within any Java code which is processed by the FacesServlet, which covers all JSF artifacts, such as managed beans and phase listeners. The article only shows how to manually create the FacesContext, but this approach is ultimately useless. The FacesContext is just an abstraction of everything already available by standard Servlet API such as HttpServletRequest, HttpSession, ServletContext, etc. Just use them directly the same way as JSF is doing "under the hoods".

    You have 2 options:

    1. Use a JSF PhaseListener instead. Depending on the concrete functional requirement which you didn't tell anything about, this may be a rather clumsy solution/workaround.

    2. Don't use JSF-provided Flash scope facility, but homebrew one yourself. The principle is rather simple: set a cookie on initial request, send a redirect, in the redirected request lookup the cookie and remove it (so that it's not there anymore on any subsequent request). That's exactly how the JSF Flash scope works under the hoods. See also Set notification message as request attribute which should show after sendRedirect for a concrete example.

    0 讨论(0)
提交回复
热议问题