会话范围的托管bean在过滤器中不可用作会话属性 [英] Session scoped managed bean not available as session attribute in filter
问题描述
遵循 JSF HTTP会话登录教程后,我尝试单击页面并将其重定向我总是到登录页面(没有CSS).我尝试使用以下代码进行调试:
After following the JSF HTTP Session Login tutorial, i tried clicking on pages and it redirected me always to the login page (without css). I tried debugging using the code below:
Enumeration<String> attributeNames = wrappedRequest.getSession().getAttributeNames();
while(attributeNames.hasMoreElements()) {
System.out.println(attributeNames.nextElement());
}
发现我希望返回的课程是
and found that the class I expected to be return at
ConnectionManager manager = (ConnectionManager) wrappedRequest.getSession()
.getAttribute("connectionManager");
未返回.如服务器日志中所示,返回了其他一些类而不是ConnectionManager类.
wasn't returned. Some other class was returned instead of ConnectionManager class as seen in the server log.
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.我能知道为什么这是回报吗?
EmployeeManager is another managed bean. Can I know why this is return instead?
推荐答案
该答案基于 ConnectionManager
是JSF托管bean.但是,基于会话中特定于CDI的对象的存在,您似乎正在使用CDI @Named
而不是JSF @ManagedBean
来管理Bean(本身就是一件好事).
That answer was based on the ConnectionManager
being a JSF managed bean. However, based on presence of CDI-specific objects in the session, it looks like that you're using CDI @Named
instead of JSF @ManagedBean
to manage beans (which is at its own a Good Thing though).
您可以将其 @Inject
放入过滤器中,而不是从HTTP会话中手动获取它.
You could just @Inject
it into the filter instead of manually grabbing it from the HTTP session.
@Inject
private ConnectionManager connectionManager;
另请参见:
- 按名称获取JSF托管bean任何与Servlet相关的类
- 支持bean(@ManagedBean)或CDI Beans(@命名)?
这篇关于会话范围的托管bean在过滤器中不可用作会话属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!