2

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

Community
  • 1
  • 1
blo0p3r
  • 6,790
  • 8
  • 49
  • 68
  • Look thru your server logs. Your session scoped bean probably contains member variables (which you should have marked as `transient`) that are not serializable. As a result, sending the contents of your `ViewScoped` bean to the client (in `javax.faces.STATE_SAVING_METHOD = client`) will fail. – kolossus Sep 21 '12 at 05:55
  • @kolossus Checked through my server logs and couldn't find anything. My session scoped bean only contains a `HashMap>`, getter + setter + 3 helper functions. – blo0p3r Sep 21 '12 at 12:49
  • `@SessionScoped` is from `javax.faces.bean` package, right? If it were from `javax.enterprise.context` package (CDI), then it'd be unrecognized and ignored and the JSF managed bean would behave like `@NoneScoped` which confirms the symptoms you're seeing. – BalusC Sep 21 '12 at 13:54
  • @BalusC Indeed my `@SessionScoped` is from `javax.faces.bean.SessionScoped`. Also made sure that I am using `javax.faces.bean.ManagedBean`. I have added imports used in question code. – blo0p3r Sep 21 '12 at 14:05
  • Have you looked in your browser's developer console? specifically the network view? look at what is sent back and forth for the ajax requests, to make sure that the view is being serialized and that the right client ids are being sent back and forth for the ajax ops, and also no hidden FacesMessages are queued for your information. – kolossus Sep 21 '12 at 17:47
  • @kolossus no hidden FacesMessages. Log is cleared. I did check the browser's developer console and everything seems fine. I fear the problem in not in the communication. Situation being that even without refreshing, on the ajax call only `displayResults.followingBean.followingThese` gets updated. On the same call `following.followingThese` doesn't get updated. On a refresh, all data gets lost. The Session Scoped bean NEVER gets updated. – blo0p3r Sep 21 '12 at 18:22
  • Could you implement both `@PostConstruct` and `@PreDestroy` in your SessionScoped bean and a PhaseListener for all phases? So we can see if indeed the bean is destroyed and when it's happening. – kolossus Sep 23 '12 at 05:51

0 Answers0