I'm currently trying to save search criteria attributes to the session between two pages: search page and edit page. The goal is to save the three variables: sYear, submission, collectionPeriod. I'm adding these to the session here below in the Search screen controller:
request.getSession().setAttribute("sYearSave", sYear);
request.getSession().setAttribute("submissionSave", submission);
request.getSession().setAttribute("collectionPeriodSave", collectionPeriod);
In the edit screen controller, I set a BooleanisFromEditScreen
to true.
This is so I know that I'm coming from the edit screen. I do print out the variables and I do get the values correctly here in the edit controller screen.
request.getSession().setAttribute("isFromEditScreen", new Boolean(true));
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
But the problem is when I use a back button to go back to the Search screen, the search criteria sYearSave, collectionPeriodSave, and submissionSave
values return NULL.
For some reason, the isFromEditScreen
boolean works just fine and returns true.
It actually enters the statement but the search criteria return null.
The Search controller code is below:
if (isFromEditScreen != null && isFromEditScreen == true) {
System.out.println("Inside isFromEditScreen ==== true");
sYear = (String)request.getSession().getAttribute("sYearSave");
collectionPeriod = (String)request.getSession().getAttribute("collectionPeriodSave");
submission = (String)request.getSession().getAttribute("submissionSave");
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
System.out.println("sYearSave ==== " + sYearSave);
System.out.println("submissionSave ==== " + submissionSave);
System.out.println("collectionPeriodSave ==== " + collectionPeriodSave);
System.out.println("isFromEditScreen set in else ==== " + isFromEditScreen);
}
Any help would be greatly appreciated!