ViewExpiredException when i use @ViewScoped

后端 未结 2 1150
醉酒成梦
醉酒成梦 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.

      
          org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
          false
      
      

      Note that the view scoped bean will still be lost whenever you restart the server.

提交回复
热议问题