I am using HttpSession as an instance variable like
@ManagedBean
@ViewScoped
public class CountryPages_Detail {
private HttpSession session;
public CountryPages_Detail() {
session = ConnectionUtil.getCurrentSession();
} //end of constructor
public String preview() {
session.setAttribute("countryDetailImageNames", imageNames);
session.setAttribute("countryDetailImages", images);
session.setAttribute("countrySummary", countrySummary);
return "countryPages_View?faces-redirect=true";
} //end of preview()
} //end of class CountryPages_Detail
ConnectionUtl Class:
public static HttpSession getCurrentSession() {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
HttpSession currentSession = (HttpSession) externalContext.getSession(false);
if (currentSession != null) {
return currentSession;
} else {
return null;
}
} //end of getCurrentSession()
I want to ask is this right way? Actually i was using in my web.xml
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
But when i changed it to <param-value>client</param-value>
, then first i got the exception that one of my class is not serializable, after making it serializable now i am getting exception that
SEVERE: Error Rendering View[/index.xhtml]
java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
....
When using server it was running fine. Why? I want to ask when we server in param-value
then all our managed bean that are in viewScope(@ViewScoped) reside on server, and when we change it to client in then all our @ViewScoped managed bean reside on client? Also if my beans are not in @ViewScoped, then does javax.faces.STATE_SAVING_METHOD element create any difference? Means STATE_SAVING_METHOD option relates to only @ViewScoped or it also effects @RequestScope or @SessionScopr or other scopes?
thanks