ViewExpiredException when i use @ViewScoped

后端 未结 2 1089
醉酒成梦
醉酒成梦 2021-01-06 19:12

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

相关标签:
2条回答
  • 2021-01-06 19:52

    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:

    1. Let your view scoped bean implement Serializable.

    2. 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.

    0 讨论(0)
  • 2021-01-06 19:54

    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>
    
    0 讨论(0)
提交回复
热议问题