40

I'm getting these messages:

[#|2010-07-30T11:28:32.723+0000|WARNING|glassfish3.0.1|javax.faces|_ThreadID=37;_ThreadName=Thread-1;|Setting non-serializable attribute value into ViewMap: (key: MyBackingBean, value class: foo.bar.org.jsf.MyBackingBean)|#]

Do these mean that my JSF backing beans should implement Serializable? Or are they refering to some other problem?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
egbokul
  • 3,794
  • 4
  • 33
  • 50

3 Answers3

65

Yes, you understood it correctly. The view is basically stored in the session scope. The session scope is in JSF backed by the Servlet's HttpSession. All session attributes are supposed to implement Serializable, this because the average servletcontainer may persist session data to harddisk among others to be able to share with other servers in a cluster, or to survive heavy load, or to revive sessions during server restart.

Storing raw Java objects on harddisk is only possible if the respective class implements Serializable. Then ObjectOutputStream can be used to write them to harddisk and ObjectInputStream to read them from harddisk. The servletcontainer manages this all transparently, you actually don't need to worry about it. JSF is just giving a warning so that you understand the risks.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
0

Beans that use session, application, or conversation scope must be serializable, but beans that use request scope do not have to be serializable. Source: https://docs.oracle.com/javaee/6/tutorial/doc/gjbbk.html

-2

Yes, Backing Beans / Managed Beans are basically meant to persist the state of the view, so it should be implemented serialization, but UI Components may not allow it to serializable and JSF Runitime will show you errror/ warning message. one thing you can do is mark such component transient in your MBeans.

Thanks.

Ambrish
  • 175
  • 1
  • 6
  • 1
    This does not apply to request or application scoped JSF managed beans. As to UI components, you should simply never assign an UI component as an instance variable of a managed bean in a scope broader than the request scope. Doing so is simply bad design. See also a.o. http://stackoverflow.com/questions/14911158/ – BalusC Jun 22 '15 at 14:38