Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF backing bean should be serializable?

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?

like image 226
egbokul Avatar asked Jul 30 '10 14:07

egbokul


People also ask

Why Java Beans are serializable?

The Serializable interface provides automatic serialization by using the Java Object Serialization tools. Serializable declares no methods; it acts as a marker, telling the Object Serialization tools that your bean class is serializable.

When to use Java serializable?

Implement the Serializable interface when you want to be able to convert an instance of a class into a series of bytes or when you think that a Serializable object might reference an instance of your class. Serializable classes are useful when you want to persist instances of them or send them over a wire.

Why should we serialize objects in Java?

Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage. Deserialization is the process of converting Object stream to actual Java Object to be used in our program.

What is purpose of serialization of an object?

Serialization in Java is the concept of representing an object's state as a byte stream. The byte stream has all the information about the object. Usually used in Hibernate, JMS, JPA, and EJB, serialization in Java helps transport the code from one JVM to another and then de-serialize it there.


1 Answers

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.

like image 166
BalusC Avatar answered Sep 18 '22 21:09

BalusC