Search code examples
javajsf-2richfacesmyfaces

MyFaces @ViewScoped throws NotSerializableException even with server setting


So I wish to use ViewScoped and when I set the state saving method to client the page will throw a NotSerializableException and the page will forward to the error page. When I switch to server state saving, the exception is still thrown but the page will load.

I read through many questions and answers and was under the impression that the combination of ViewScoped/server state saving will eliminate the need to have everything marked as Serializable. Anyone see this issue?

Richfaces 4.1/Myfaces 2.1.5


Solution

  • I think setting this servlet context parameter will solve the issue:

    <context-param>
      <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
      <param-value>false</param-value>
    </context-param>
    

    This will prevent MyFaces from serializing the state before saving it in the session. Doing so is the default reason. I think it's for saving memory.