On Fri, 22 Nov 2002, Derek Richardson wrote:

> Date: Fri, 22 Nov 2002 19:27:48 -0500
> From: Derek Richardson <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: Struts Users Mailing List <[EMAIL PROTECTED]>
> Subject: Using subclasses of class specified in form-bean element
>
> I have a superclass, RuleForm, with some subclasses, like ImportRule and
> ExportRule. In my struts-config file, I specify that my actions deal
> with a form-bean named ruleForm in session scope which is defined as
> type RuleForm. However, the actual class of the bean will usually be
> ImportRule or ExportRule, not RuleForm.
>
> Or this is what I'd like to work. I am seeing behavior that looks like
> Struts will not accept the subclasses as substitutes for the superclass.
> But this behavior may be due to my application logic, not Struts. So I'm
> hoping someone will tell me whether Struts supports this or not.
>
> The Struts user guide and JavaDoc for ActionFormBean say that the type
> attribute contains the java class type for the form bean. I just find
> this somewhat ambiguous, given inheritance.
>

More precisely, the value you specify for "type" in a <form-bean>
declaration is the fully qualified class name of the class that Struts
will ask to instantiate a new instance whenever a new form bean is
required.

Struts uses the Class.newInstance() method for this purpose.  Therefore,
you must specify the name of a concrete class that has a public no-args
constructor.

If you always precreate your form beans (so that Struts doesn't have to),
you could use the superclass name in the <form-bean> element.  At least
with recent nightly builds of 1.1, such a bean would pass the "instanceof"
test that Struts performs to see if the existing bean is of the correct
class.  However, making sure this happens in all scenarios can be pretty
complicated.

> Thanks,
>
> Derek Richardson
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to