简体   繁体   中英

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. In my one of the projects I have a ManagedBean, SessionScoped like below

@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. The second page just displays the input data, accessing it from the bean. ( <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. I was expecting that while the bean is session scoped it should still be available in the current session.

确保使用的是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. Up to now I havent´t figured out the semantics of the @ManagedBean annotation. So I cannot explain what makes the difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM