I have the following SessionScoped bean: As you can see, I initialize some variables that will be needed later on for a page load.
@ManagedBean
@SessionScoped
/*
* CassandraBean is the backing bean for holding and managing information that is specific to each user session.
*/
public class CassandraBean implements Serializable {
private static final long serialVersionUID = 3542953038465572524L;
private ResultSet rs;
private HashMap<String, TInfo> tur;
private ArrayList<ErrorInfo> errors;
private ArrayList<String> selected;
private String selectedErrCode="114";
private LocalDate endDate=LocalDate.now();
private LocalDate startDate=LocalDate.of(endDate.getYear()-4, endDate.getMonthValue(), endDate.getDayOfMonth());
private CassandraManager cm;
/*
* Creates a new instance of this bean, connects to the server and loads up data
* Also starts a timer to refresh the data every 10 minutes.
*/
public CassandraBean() {
cm=new CassandraManager("192.168.129.136", "keyspacename");
createData();
selected=new ArrayList<String>();
selected.add("B01");
Timer timer = new Timer();
//queries the DB every 10 mins
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
createData();
}
}, 10*60*1000, 10*60*1000);
}
After the constructor is called, everything is fine. All variables have value when checked in the debugger.
However when I navigate to a different page using a method in another bean, the variables selected and selectedErrCode lose their values. They are not set to null, but selectedErrCode becomes an empty string and selected becomes an empty ArrayList.
The problem with this is that I need those values to stay there because then the following method is called.
public ArrayList<ErrorInfo> getErrors(){
getErrorData(selected, selectedErrCode, startDate, endDate);
return errors;
}
This method is called by a datatable in my xhtml page to fill up a table. Once the page has loaded the user can query using an onpage input form and the selected, selectedErrCode, startDate and endDate will be taken from the input forms.
I am on JBoss 6.3 EAP if that helps.