FacesContext#getCurrentInstance()在Filter#doFilter()中返回null [英] FacesContext#getCurrentInstance() returns null in Filter#doFilter()
问题描述
在
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
我想使用此会话
FacesContext.getCurrentInstance().getExternalContext().getSession(false);
但是我意识到FacesContext.getCurrentInstance()
返回null
.我知道我可以改为使用((HttpServletRequest) req).getSession(false)
进行会话,但是我的具体问题是:为什么在doFilter()
方法中的人脸上下文null
是什么?
But I realised that FacesContext.getCurrentInstance()
returns null
. I know that I can get the session using ((HttpServletRequest) req).getSession(false)
instead, but my concrete question is: why is the faces context null
in the doFilter()
method?
我正在使用MyFaces 1.1.
I'm using MyFaces 1.1.
推荐答案
FacesContext
,因为对象直接绑定到JSF请求处理生命周期,因此只能在标准JSF中使用 (用户驱动)的请求-响应过程.实际对象本身存储在与ManagedBean相对的JSF请求处理期间运行的线程中.
FacesContext
as an object is tied directly to the JSF request processing lifecycle and as a result is only available during a standard JSF (user-driven) request-response process. The actual object itself is stored in a thread that runs during the processing of a JSF request, vis-a-vis a ManagedBean.
但是. BalusC概述了一些在处理生命周期之外使用对象的步骤
But. BalusC has outlined some steps to get your hands on the object outside of the processing lifecycle here. :)
这篇关于FacesContext#getCurrentInstance()在Filter#doFilter()中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!