简体   繁体   English

JSF-访问SessionScoped托管bean

[英]JSF - Accessing a SessionScoped managed bean

I'm quite new in JSF and I'm doing some basic things to get a feeling of how one should work with it. 我是JSF的新手,并且正在做一些基本的事情来了解如何使用它。 In my one of the projects I have a ManagedBean, SessionScoped like below 在我的一个项目中,我有一个ManagedBean,SessionScoped,如下所示

@ManagedBean(name="user")
@SessionScoped
public class User implements Serializable
// Having a couple of String properties (with setters and getters).

Now, in one page in a form I have a <h:inputText id="firstName" value="#{user.firstName}" ... /> which I would expect to get a value from the user and put it in my bean's property. 现在,在表单的一页中,我有一个<h:inputText id="firstName" value="#{user.firstName}" ... /> ,我希望可以从用户那里得到一个值并将其放入我的豆的财产。 The second page just displays the input data, accessing it from the bean. 第二页仅显示输入数据,可以从Bean访问它。 ( <h:outputText value="${user.firstName}"/> ). <h:outputText value="${user.firstName}"/> )。

The problem is that if after that I go in a third page (just by typing the URL) and I'm trying to use the same line to display once again the data from the bean, no data gets displayed. 问题是,如果之后我进入第三页(仅通过输入URL),而我试图使用同一行再次显示Bean中的数据,则不会显示任何数据。 I was expecting that while the bean is session scoped it should still be available in the current session. 我期望当bean在会话范围内时,它应该在当前会话中仍然可用。

确保使用的是import javax.faces.bean.SessionScoped,而不是javax.enterprise ...;

Maybe someone is still interested in this: I encountered the same behavior as described above. 也许有人对此仍然感兴趣:我遇到了与上述相同的行为。 The solution was finally to replace @ManagedBean through @Named. 解决方案最终是通过@Named替换@ManagedBean。 Up to now I havent´t figured out the semantics of the @ManagedBean annotation. 到目前为止,我还没有弄清楚@ManagedBean批注的语义。 So I cannot explain what makes the difference. 因此,我无法解释造成差异的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JSF SessionScoped托管bean - 重启服务器后,spring bean的注入为null - JSF SessionScoped managed bean - injection of spring bean is null after restarting server 在JSF页面中访问SessionScoped Bean - Accessing SessionScoped Beans in JSF pages 在Servlet中访问会话范围内的JSF托管Bean,是否保证该会话与JSF使用的会话相同? - Accessing a session scoped JSF managed bean in a servlet, is this guaranteed to be the same session as JSF uses? 在同一会话中多次从另一个SessionScoped bean访问一个SessionScoped bean创建了一个新实例 - Accessing a SessionScoped bean from another SessionScoped bean more than once in same session creates a new instance JSF注入了sessionscoped bean的方法调用成为空指针 - JSF injected sessionscoped bean's method invocation become null pointer 如何在JSF托管Bean中创建,访问和销毁会话? - How to create, access and destroy session in JSF managed bean? 监听用户 session 何时在 JSF 托管 bean 中结束 - Listening to when the user session is ended in a JSF managed bean JSF在请求范围的Bean中注入和访问会话范围的ManagedBean - JSF injecting and accessing Session Scoped ManagedBean in a Request Scoped Bean WELD + GF4 + SessionScoped:有时错误的bean? - WELD + GF4 + SessionScoped: Sometimes wrong bean? CDI SessionScoped Bean生成大量会话 - CDI SessionScoped Bean generating lots of sessions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM