Session 在会话中存储表单字段值,并根据需要在多个页面上获取该值

Session 在会话中存储表单字段值,并根据需要在多个页面上获取该值,session,jsf-2,Session,Jsf 2,我有一个JSF表单,其中有一个字段(textfield),textfield中有一个值,比如说profileId,我需要在许多页面中使用它,那么我们如何在会话中存储它,以及如何根据需要检索它呢 简单地说,在JSF会话中设置一个变量值并获取它。将其绑定到会话范围的托管bean @ManagedBean @SessionScoped public class Profile { private Long id; // ... } 与 <h:inputText value=

我有一个JSF表单,其中有一个字段(textfield),textfield中有一个值,比如说
profileId
,我需要在许多页面中使用它,那么我们如何在会话中存储它,以及如何根据需要检索它呢


简单地说,在JSF会话中设置一个变量值并获取它。

将其绑定到会话范围的托管bean

@ManagedBean
@SessionScoped
public class Profile {

    private Long id;

    // ...
}

<h:inputText value="#{profile.id}" />
@ManagedBean
@ViewScoped
public class OtherBean {

    @ManagedProperty("#{profile}")
    private Profile profile;

    public void submit() {
        System.out.println(profile.getId());
    }

    // ...
}