[英]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.