java.io.NotSerializableException when @ViewScoped is used

流过昼夜 提交于 2019-12-04 07:30:33
Danubian Sailor

You didn't provide the settings from web.xml, but if the javax.faces.STATE_SAVING_METHOD is set to client, the view is always serialized, so the NotSerializableException will always occur.

You should always make your JSF beans serializable, because application server may want to serialize the session, so all session-scoped and view-scoped beans, even if state saving is set to server.

But if the server isn't serializing your session, you won't get that error on session scoped beans. But if view is serialized on client, it means that all view scoped beans are serialized to string that is sent as hidden field with all requests, and the JSF engine is detecting that your beans are not serializable.

NotSerializableException occurs only when the server tries to actually serialize your beans!

You have to implement Serialization in you bean

public MyJSFBean implements Serializable{
//Bean coding
}

In @ViewScoped bean it is required because the screen data is valid for view not for just one request. In case of @SessionScoped bean data is stored in the session which takes care of serialization of data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!