You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rh...@rdg.boehringer-ingelheim.com on 2001/03/20 22:24:33 UTC

more on ActionForms

Struts appears to be ignoring the ActionForms that I am trying to manually
put in the session. If the ActionForm is not the same class type as what is
defined in struts-config.xml then Struts ignores it and creates a new one
when the page is processed. Is this the intended behavior?

If so, I would like to propose a slight change to the logic Struts uses when
creating an instance of an action form. Currently, as I understand it,
Struts will check to see if an instance of the ActionForm exists in the
session based on the name assigned to the attribute and the class type of
the attribute. If either do not match, then Struts creates a new ActionForm
of the type defined in the mapping. What about changing this so that the
object in the session can be of the same type, *or* a subclass of the class
specified in the struts-config.xml? Can anyone think of a scenario where
this would cause problems?

I am having problems with the design of my application because of this. If
this functionality was supported things would become simpler and the app
would be more extensible.

Comments?

-Bob


-----Original Message-----
From: Hayden,Robert IT BIP-US-R 
Sent: Tuesday, March 20, 2001 1:09 AM
To: struts-user@jakarta.apache.org
Subject: Object oriented question regarding ActionForms



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