I have problem with my h:commandButton \"Login\": when I use @ViewScoped and push this button there is ViewExpiredException, but when I use @SessionScoped, there isn\'t any
Your concrete problem is caused because your view scoped bean is not serializable and hence MyFaces is not able to save it in the view state. MyFaces by default serializes the whole state in session instead of just referencing the state in session and having the container to serialize it if necessary.
There are basically 2 solutions:
Let your view scoped bean implement Serializable
.
Tell MyFaces to not serialize the whole view state in session.
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
Note that the view scoped bean will still be lost whenever you restart the server.
http://arjan-tijms.omnifaces.org/p/jsf-22.html#1127
MyFaces implementation of JSF2.1 had org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
default to true
, wheres Mojarra had com.sun.faces.serializeServerState
default to false
.
From JSF2.2 onwards this will be standardised via javax.faces.SERIALIZE_SERVER_STATE
which defaults to false
.
<context-param>
<param-name>javax.faces.SERIALIZE_SERVER_STATE</param-name>
<param-value>true</param-value>
</context-param>