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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Using subclasses of class specified in form-bean element
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]
Re: Using subclasses of class specified in form-bean element
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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Using subclasses of class specified in form-bean element
-Original Message- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 7:37 PM To: Struts Users Mailing List Subject: Re: Using subclasses of class specified in form-bean element 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 for the precise answer. One thing I'm unclear about. Does the last sentence mean this functionality is supported by Struts but it's pretty complicated to code an application correctly or does it mean that it's pretty complicated to tell whether Struts will always behave this way? This is sounding like a road I don't want to go down. But I am working with wizards that determine the subclass on the second or third page and subclasses would be a nice way to support back-button functionality in a generic way. While on the topic, does anyone have a reference for best practices for coding wizards with Struts? Derek Richardson -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]