【问题标题】:Session scoped managed bean not available as session attribute in filter会话范围的托管 bean 不能用作过滤器中的会话属性
【发布时间】:2023-03-30 13:50:01
【问题描述】:

遵循JSF HTTP Session Login 教程后,我尝试点击页面,它总是将我重定向到登录页面(没有css)。我尝试使用以下代码进行调试:

Enumeration<String> attributeNames = wrappedRequest.getSession().getAttributeNames();
    while(attributeNames.hasMoreElements()) {
                System.out.println(attributeNames.nextElement());
    }

并发现我期望返回的课程

ConnectionManager manager = (ConnectionManager) wrappedRequest.getSession()
            .getAttribute("connectionManager");

没有返回。如服务器日志中所示,返回了其他一些类而不是 ConnectionManager 类。

Info:   employeeManager
Info:   org.jboss.weld.context.beanstore.http.LockStore
Info:   com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap
Info:   org.jboss.weld.context.conversation.ConversationIdGenerator
Info:   org.jboss.weld.context.ConversationContext.conversations
Info:   javax.faces.request.charset

EmployeeManager 是另一个托管 bean。我可以知道为什么这是 return 吗?

【问题讨论】:

    标签: jsf servlet-filters managed-bean session-scope


    【解决方案1】:

    该答案基于 ConnectionManager 是 JSF 托管 bean。但是,基于会话中 CDI 特定对象的存在,您似乎正在使用 CDI @Named 而不是 JSF @ManagedBean 来管理 bean(尽管这本身就是一件好事)。

    您可以将其 @Inject 放入过滤器,而不是手动从 HTTP 会话中获取它。

    @Inject
    private ConnectionManager connectionManager;
    

    另见:

    【讨论】:

      猜你喜欢
      • 2012-06-27
      • 2012-12-26
      • 2014-06-30
      • 2013-01-05
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      相关资源
      最近更新 更多