You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shasirekha Engala <sh...@patni.com> on 2006/02/22 05:05:18 UTC

Reg: DynaActionforms and ActionForms

Hi,
    I want some information regarding the difference between DynaActionforms
and  ActionForms and advantages of DynaActionforms over  ActionForms. I need
the code of subclassing the dynaforms and using it. For example, I am having
a BaseForm with the variables pageno( page number), action (action to be
performed like save, update, delete, create....). This form I have declared
in struts-config.xml. Now all the other forms I am creating should extend my
BaseForm. How can I do this using DynaActionForms in struts-config.xml?
Kindly reply to this mail as soon as possible as it is bit urgent.


Thanks and Regards
Shasi




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Reg: DynaActionforms and ActionForms

Posted by Laurie Harper <la...@holoweb.net>.
Shasirekha Engala wrote:
> Hi,
>     I want some information regarding the difference between DynaActionforms
> and  ActionForms and advantages of DynaActionforms over  ActionForms. I need
> the code of subclassing the dynaforms and using it. For example, I am having
> a BaseForm with the variables pageno( page number), action (action to be
> performed like save, update, delete, create....). This form I have declared
> in struts-config.xml. Now all the other forms I am creating should extend my
> BaseForm. How can I do this using DynaActionForms in struts-config.xml?
> Kindly reply to this mail as soon as possible as it is bit urgent.

The main point of DynaActionForm and friends is so that you can 
configure form beans in your struts-config.xml without having to write 
any supporting code. Unfortunately, in 1.2.x, there's no mechanism to 
achieve what you want.

The good news is that this feature is one of the things that 1.3.x adds. 
You can do something like this:

   <form-bean name="base">
     ... properties ...
   </form-bean>

   <form-bean name="mybean" extends="base">
     ... more properties ...
   </form-bean>

There isn't yet a release of Struts Action 1.3, though it's getting 
close. In the meantime, you'd need to use a nightly build.

If that's not acceptable for your project, you have at least a couple of 
other options. One is simply to copy-paste the common properties into 
each form-bean declaration, which isn't great but may be OK if you only 
have a few common properties. Another, which is really just a refinement 
of the first option, is to use a bit of XML trickery.

Basically, you'd add an internal DTD subset declaring an entity with 
your common form-bean properties:

<!DOCTYPE struts-config [
<!ENTITY common-props "
   <property name="pageno" type="java.lang.String"/>
   ...
"]>

Then, in your form-bean declarations, you include the entity:

   <form-bean name=...>
     &common-props;
     ... more properties ...
   </form-bean>

Obviously, the Struts Action 1.3 'extends' feature is by far the cleaner 
way to go if you can justify using a pre-release version.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org