user244597
user244597

Reputation:

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.

Upvotes: 3

Views: 8806

Answers (2)

Noesis
Noesis

Reputation: 13

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.

Upvotes: 0

Daniel
Daniel

Reputation: 81

Make sure you are using import javax.faces.bean.SessionScoped, instead of javax.enterprise...;

Upvotes: 8

Related Questions