• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serializable Action Forms? Why?

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Struts documentation (http://struts.apache.org/api/index.html) says we should serialize ActionForms:

Because ActionForms are JavaBeans, subclasses should also implement Serializable, as required by the JavaBean specification. Some containers require that an object meet all JavaBean requirements in order to use the introspection API upon which ActionForms rely." (16Oct2004)



Why?

The ActionForm class already implements java.io.Serializable. Are not the subclasses extended from this class automatically serialized by inheritance? In other words, why implement serializable again?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow. Great question. I never noticed it before and it's right there in the ActionForm's javadoc.

Yes, if ActionForm is Serializable its subclasses implement Serializable.

Speople specify "implements Serializable" in bean subclasses as a gentle reminder. It's still weird that the Javadoc says that. Maybe it was intended as a reminder any non-Serializable class variable should be declared transient.
 
Charles McGuire
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for acknowledging the question. The date on the JavaDoc is relatively recent, too. It is weird, and no one has a good answer; everyone I ask seems equally stumped, even my Struts instructor.

Oh, the humanity!

 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can tell you that awhile ago a version of Tomcat I used threw a stack trace on shutdown and startup (only after the first time the app had been started) complaining that some of my ActionForm classes, which I had kept in session scope, were not serializable. I believe this had something to do with the way Tomcat tried to save and restore sessions; just a guess, I didn't really look into it too hard. Implementing serializable took care of the situation.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charles,
I took that to mean that the subclass should observe the contract of Serializable, not just implement the interface. For example, all of the fields must be Serializable.

Personally, I like to implement Serializable explicitly as a reminder.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic