You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Derek Richardson <De...@appiancorp.com> on 2002/11/23 01:27:48 UTC
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.
Thanks,
Derek Richardson
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Using subclasses of class specified in form-bean element
Posted by Eddie Bush <ek...@swbell.net>.
Derek Richardson wrote:
>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.
>
Struts will use whichever type you specify for the form to instantiate
it, so you need to do one of two things:
- manually create the form before Struts has a reason to
- tell Struts the real type of the form
>Thanks,
>
>Derek Richardson
>
--
Eddie Bush
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Using subclasses of class specified in form-bean element
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Fri, 22 Nov 2002, Derek Richardson wrote:
> Date: Fri, 22 Nov 2002 19:27:48 -0500
> From: Derek Richardson <De...@appiancorp.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> 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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>