I like the basic approach - but I'd modify it to do the following:
1. Define an INTERFACE that your Astract bean class implements
2. The form beans can then EITHER implement the interface or subclass the
abstract class (or both - this is redundant, but it works).
3. Have the Action class operate on THE INTERFACE instead of the Abstract
class.
4. In your struts-config.xml, make sure you still specify the concrete form
beans in the action mappings and form-bean entries.
If you don't use the concrete classes in the struts-config, then in
situations where a form bean can be reused, you won't be ensured that the
correct concrete form bean class will be reused.
An alternative approach would be:
- Eliminate the abstract class altogether
- Specify only an interface
- Have your form beans implement the interface
- Have your action class operate ONLY on the interface.
- Specify the concrete classes in your struts-config.xml
The trade-off between the two approaches is that by using an Abstract
class, you may reduce the coding you do - as long as the coding between the
three form bean classes is very similar. If each form bean subclasses the
abstract class then ends up having to override its methods, then
eliminating the abstract class may be a better approach.
FWIW -
Kevin
Viet Kevin <[EMAIL PROTECTED]> on 04/22/2002 09:59:28 AM
Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>
To: struts mailing list <[EMAIL PROTECTED]>
cc:
Subject: form bean life cycle
Hello all, I a mwondering about this ?
I have a form bean declared abstract and I have subclassed it
into three concrete form bean classes that I use, this works OK.
Then, I want now, to use an action that does not require to know
anything about these concretes implementations: I want my
action to work on the interface of the abstract form, for this
I have declared an action-mapping to use a form bean
of the abstract class and from the session scope, I thought
that struts won't try to create the form again (actually it
can't because the form class is abstract), infortunatelly
the logs of struts told me that struts have tried to create
it.
My question is why do struts try to recreate the action form
if it can be found from the session
=============================================================
-- KeV --
=============================================================
--
To unsubscribe, e-mail: <
mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <
mailto:[EMAIL PROTECTED]>
---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure. If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited. If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>