Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sharing a session-scoped JSF bean between two WAR applications

843844Oct 10 2008 — edited Oct 21 2009
Hi Experts,

I have a JSF session-scoped bean called UserBean which looks as follow:
public class UserBean {
    private String user;

    public void setUser(String user) {
        this.user = user;
    }

    public String getUser() {
        return user;
    }
}
I also have two request-scoped page beans that are identical but contained in seperate WAR applications:
public class PageBean {
    public void setUser(String user) {
        getUserBean().setUser(user);
    }

    public String getUser() {
        return getUserBean().getUser();
    }

    private UserBean getUserBean() {
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        ELResolver elResolver = FacesContext.getCurrentInstance().getApplication().getELResolver();
        return (UserBean)elResolver.getValue(elContext, null, "userbean");
}
I package all of these beans together in an EAR file, with the UserBean contained in a JAR in the lib folder, and the two WARs placed under the root, as such:
EAR
|___ PageBean1.war
|___ PageBean2.war
|___ lib
       |___ UserBean.jar
Now, if I load the PageBean1 application and call setUser followed by getUser in another browser window (on PageBean1) it works fine and vice versa for PageBean2. If I, however, call setUser on PageBean1 but getUser on PageBean2, or vice versa, the method returns null, indicating that they have two different instances of UserBean, even though it is session-scoped. I need them to refer to the same instance.

Any ideas?
Thank you,
Ristretto
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2009
Added on Oct 10 2008
6 comments
501 views