0

我有一个过滤器:UserSessionFilter.java,我用来处理用户会话和一个ApplicationScopedbean:Config.java主要让我可以访问DAO factory.

配置文件

@ManagedBean (eager = true)
@ApplicationScoped
public class Config implements Serializable {...

过滤器调用一个方法Config来获取一个DAOFactory对象:

过滤方式

@Override
public void init(FilterConfig filterConfig) {
    daoFactory = Config.getInstance().getDAOFactory();
}

配置方法

public static Config getInstance() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        return (Config) facesContext.getApplication().evaluateExpressionGet(
                 facesContext, "#{config}", Config.class);
}

我的问题是facesContext设置为null. 这个问题在从 切换Mojarra到后开始出现MyFaces,尽管这似乎很奇怪。

4

1 回答 1

0

FacesContext cannot be used inside the Filter. See this or this answers. Reason:

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

于 2014-02-15T16:04:39.680 回答