I have an object oriented question related to how Struts instantiates an
ActionForm. What I am trying to do is utilize a factory for creation of my
ActionForms. In my application, I have a base (abstract) ActionForm class
called Fermentation, and subclasses FermentationYeast, FermentationEcoli,
etc...  The factory is called from my Action servlet to create the
appropriate instance of an ActionForm (a subtype of Fermentation). Then I
save the newly created ActionForm in the session. The object type that gets
saved in the session is the subtype, but in my Struts config I am specifying
the base type. I want Struts to read this object from the session, but
Struts always creates a new ActionForm of the base type. I want it to find
and use the subtype!

For example, the Action servlet calls the factory and the factory returns a
FermentationYeast. This object is saved in the session, and then I forward
to the EditFermentation page. The EditFermentation page is mapped in the
Struts config to use a Fermentation form, so Struts does not recognize the
FermentationYeast that is already in the session and it creates a new
ActionForm. Even though a FermentationYeast *is a* Fermentation, Struts does
not seem to support this. I think it would be helpful if Struts supported
generalization... or if it does and I am missing something here please let
me know :) Or, If you think I should change my design, please let me know
this as well.

I think I have a good reason to need to do this. The first page is where the
user enters common information, then the next page is loaded based on the
type of the Fermentation (ActionFrom). I could create 2 separate ActionForms
(one for the common attributes and then another for the details) but I would
like to use inheritance to model this relationship. In other words, I want
to create a single ActionForm which will be used across multiple pages, but
I want to share pages that ask for the same information.


Thanks,
Bob

Reply via email to