> Is this bad form?
Michael, IMHO you've got the right idea.
I leverage DispatchAction and DynaActionValidator form
in a similar fashion, except I take it one more step.
I group them into areas of functionality that mirror my
application.
For example, my web application has the following sections:
store front, user account, product download, bug tracking,
forums, etc...
I have a DispatchAction for each area of functionality which
I call XXXXControllers.
To go with each XXXXController I have a single DynaActionValidator
form. Validation is invoked based on the action mapping concatonated
with the operation name (/account/editAccount-saveChanges)
This greatly reduces the number of web tier classes you
have to create and maintain and makes the application components
more cohesive.
> Assuming this practice is acceptable, I need to understand how I
> can apply the same principle to forms. I have a registration
> form for new users. There is a RegistrationAction class, which
> extends DispatchAction. It currently has two methods--create()
> and update(). How can I configure this in struts-config.xml, and
> how do I get this to work with the DynaActionValidator form bean?
I created a base form bean class which extends DynaActionValidator.
Each of the form beans defined in my struts-config.xml file have
this base class as the type attribute. For example:
<form-bean name="registrationForm"
type="com.companyname.BaseForm"
dynamic="true">
<form-property name="firstName"
type="java.lang.String"/>
<form-property name="lastName"
type="java.lang.String"/>
etc....
</form-bean>
In BaseForm, I overrode the validate() so that I passed in the
action mapping concatonated with the operation name. For exampe:
String path = mapping.getPath();
String operation = request.getParameter("method");
String validationKey = path + "-" + operation;
Validator validator = StrutsValidatorUtil
.initValidator(validationKey, this,
application, request, errors, page);
This uniquely identifies the validation routines defined
in my validation.xml. For example:
<form name="/account/editAccount-saveChanges">
<field property="email"
depends="required,email,maxlength">
<arg0 key="form.account.email.displayName"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>255</var-value>
</var>
</field>
etc...
</form>
HTH,
robert
> -----Original Message-----
> From: Day, Michael-IBM/TT [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, September 22, 2002 6:30 PM
> To: [EMAIL PROTECTED]
> Subject: General Action classes question
>
>
> Hopefully someone can help clear this question up. I am trying
> to use a few DispatchActions for all Actions in my application.
>
> As an example, I have a Category data object. All actions
> performed with this object directly are encompassed in the
> CategoryAction which extends DispatchAction. I can use my
> CategoryAction class to display, insert, update, and delete a
> Category object. Is this bad form? I don't see a point in
> creating separate Actions for each "operation".
>
> Assuming this practice is acceptable, I need to understand how I
> can apply the same principle to forms. I have a registration
> form for new users. There is a RegistrationAction class, which
> extends DispatchAction. It currently has two methods--create()
> and update(). How can I configure this in struts-config.xml, and
> how do I get this to work with the DynaActionValidator form bean?
>
> Thanks for the help.
>
> __________________________________________________
> Michael Blake Day
> Nextel Communications, Inc.
> email: [EMAIL PROTECTED]
> desk: 678.966.4792
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>