I am not able to understand what is the function of this line in web.xml
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
I have read that the NetBeans default is client. I’ve just faced an issue that I have many beans in my application, and the <param-value> was set to client, so I was getting
java.io.NotSerializableException
error although my beans were Serializable (i.e. they implemented the Serializable interface.). My beans were in @ViewScope. But when I changed it to server, things are going to work. Why? What is the difference when I use client and server. Can anyone explain me with the help of an example.
Thanks
This kind of exception has usually a message in the root cause which shows the fully qualified class name of the class which doesn’t implement
Serializable. You should pay close attention to this message to learn about which class it is talking about and then let it implementSerializableaccordingly.Often, making only your managed bean classes serializable is not always sufficient. You also need to ensure that each of its properties is also serializable. Most standard types like
String,Long, etc implement all alreadySerializable. But (custom) complex types such as nested beans, entities or EJBs should each also be serializable. If something is not really implementable asSerializable, such asInputStream, then you should either redesign the model or make ittransient(and keep in mind that it will benullafter deserialization).First some background information: Why JSF saves the state of UI components on server?
The main technical difference is that the
clientsetting stores the entire view state as the value of thejavax.faces.ViewStatehidden input field in the generated HTML output and that theserversetting stores it in the session along with an unique ID which is in turn referenced as the value of thejavax.faces.ViewStatehidden input field.So, setting to
clientincreases the network bandwidth usage but decreases the server memory usage and setting toserverdoes the other way round. Setting toclienthas however an additional functional advantage: it preventsViewExpiredExceptions when the session has expired or when the client opens too many views.