Injected Session Scoped Bean in View Scoped bean duplicating

大城市里の小女人 提交于 2019-12-10 11:28:49

问题


I have a ViewScoped bean and in this bean I am injecting a SessionScoped bean. A lot of information is found on this and is pretty straight forward.

Session bean

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Following implements Serializable {
    private HashMap<Integer, ArrayList<String>> followingThese;

    //Constructors and getters+setters
    ...
}

View Bean

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean
@ViewScoped
public class DisplayResults implements Serializable {

    // Following Bean
    @ManagedProperty(value = "#{following}")
    private Following followingBean;

    // other information...
    ...

    //*and this is how this injected bean is used*
    public void startStopFollowing(int id, name) {
         followingBean.startStopFollowing(id, name);  //adds this id to followingThese
    }
}

Facelet

...
<h:outputText value="#{displayResults.followingBean.followingThese}" id="test"/>
<h:outputText value="#{following.followingThese}" id="test2"/>

...

<h:selectBooleanCheckbox value="#{results.followed}" immediate="true" 
    valueChangeListener="#{displayResults.startStopFollowing(displayResults.id, displayResults.name)}">
     <f:ajax render=":test :test2"/>
</h:selectBooleanCheckbox>

The interesting thing here is that test gets updated by clicking the checkbox but test2 doesn't. The session scoped variables never get updated. When refreshing the page, I loose all the info I had in #{displayResults.followingBean.followingThese}

Edit : The session variable doesn't get updated on an ajax call only the "injected session variable"

If I change javax.faces.STATE_SAVING_METHOD to server this code above works, but when on client, nothing. I lose all my "session" information that has been saved through the ViewScoped bean.

Edit Forgot to mention. Using JSF (Majorra) 2.1.6 on Glassfish 3.1.2.2 (just updated everything hoping that this might solve an issue).

Edit #2 Added full list of imports with code above.

Added information After trying a few things here and there, the functionalities I am looking for work no problem if I set the receiving bean to a RequestScoped OR SessionScoped. It doesn't work when set to ViewScoped. This would be all nice and dandy, but I need other functionalities I need from the view scope and this would make no sense to set my bean to session scope.

Any help is appreciated.

Edit 3

This has been logged as a bug on JIRA

来源:https://stackoverflow.com/questions/12513374/injected-session-scoped-bean-in-view-scoped-bean-duplicating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!