This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Struts and the fly likes why actionform is implements serializable ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why actionform is implements serializable ?" Watch "why actionform is implements serializable ?" New topic

why actionform is implements serializable ?

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Hi ,
My query is why actionform implements serializable ? like any other class as it implements serializable ,it then can be serialized .But why we need that ? In most cases whatever persistance is required, we just take the form bean field values(i.e the properties) and persist them in the DB .Then why the formbean itself implements serializable ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The J2EE Servlet spec states that any object that is stored in an HTTPSession object should implement Serializable. The reason for this is that application servers in a distributed environment may need to serialize sessions for storage in a Database or transmission to a different JVM. Since One of the valid scopes for an ActionForm is session, it has to be serializable in order to meet this requirement.

Consultant, Sima Solutions
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
ok .Thanks for the answer .
I have query then,I can also store any Object ,say a simple Integer Object and in that I can store that using session.setAttribute(integerVariableName), but I think Integer Object does not implement serializable ? But still it can be stored in the session .
then why it is stored then ?
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Ayan, If you look at the JDK api doc on Integer object you will find that this object and all other wrapper objects does implements Serializable.
Regarding why ActionsForms implements serializable:

- ActionForms can be stored in "session" scope. (refer struts-config.xml) and as Merrill said the session cannot be replicated to secondary server for failover if all the objects in session does not implements Serializable interface.

- However, if you application runs on just one server then you are free to objects which doesn't implement serializable interface in session. But this uncommon now.
[ October 31, 2006: Message edited by: Purushothaman Thambu ]
jQuery in Action, 3rd edition
subject: why actionform is implements serializable ?
It's not a secret anymore!