aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why actionform is implements serializable ?" Watch "why actionform is implements serializable ?" New topic
Author

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 ?
Regards,
Ayan
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.


Merrill
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 ?
Regards,
Ayan
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why actionform is implements serializable ?