JSF - Access to a managed SessionScoped bean

I am completely new to JSF and I am doing some basic things to figure out how to work with it. In my one of the projects I have a ManagedBean, SessionScoped, as shown below

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

Now on one page in the form I have <h:inputText id="firstName" value="#{user.firstName}" ... />, which I expect to receive from the user and put in my bean. The second page displays only the input data that can be obtained from the bean. ( <h:outputText value="${user.firstName}"/>).

The problem is that if after that I go to the third page (just by typing the URL) and I try to use the same line to display the data from the bean again, the data is not displayed. I was expecting that while the bean is a member of the session, it should still be available in the current session.

+3
source share
2 answers

Make sure you use import javax.faces.bean.SessionScoped, not javax.enterprise ...;

+8
source

Perhaps someone is still interested: I came across the same behavior as described above. The solution finally replaced @ManagedBean with @Named. So far I have not understood the semantics of @ManagedBean annotation. So I can’t explain what makes the difference.

0
source

Source: https://habr.com/ru/post/1727462/


All Articles