I just found out that the DynaValidatorActionForm provides this functionality (defined below).
robert > -----Original Message----- > From: Robert Taylor [mailto:[EMAIL PROTECTED]] > Sent: Sunday, June 09, 2002 6:53 AM > To: Struts Users Mailing List > Subject: RE: Struts Validator > > > Thanks Peter and Raffy, > > Using DispatchAction and the same ActionForm for common events > helps reduce > the number of presentation framework classes and also allows me to reuse > business components. > > After looking more closely at the code, it appears that validation for a > bean > is bound to the name attribute of the form element in the validation.xml > file. > > It also appears that the bean field validation rules are > extracted using the > name attribute of the form element in validation.xml and the the > validation > is > performed on those fields defined in the bean that exists in the resources > under the Validator.BEAN_KEY key. > > If this is the case, then it is possible to override > ValidationForm.validate() and pass the action mapping path as the "form > name" > and then validation for a bean could be bound to the action path > instead of > the form name. > > > public ActionErrors validate(ActionMapping mapping, HttpServletRequest > request) { > > ServletContext application = getServlet().getServletContext(); > ActionErrors errors = new ActionErrors(); > Validator validator = StrutsValidatorUtil.initValidator( > mapping.getPath(), //mapping.getAttribute(), > <============ > use path instead of form name > this, application, request, errors, page); > > try { > > validator.validate(); > > } catch (ValidatorException e) { > > log.error(e.getMessage(), e); > > } > > return errors; > > } > > In this manner I could use the same form and apply different validation > according to the action mapping. I could further qualify validation for > fields using the page identifier. > > > This, of course, is speculation since I haven't tested it. > > > Is this possible? > > > robert > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Sent: Friday, June 07, 2002 6:00 PM > > To: Struts Users Mailing List > > Subject: Re: Struts Validator > > > > > > > > I tend to think it's either you NOT use DispatchAction if you have > > different validation requirements for the same form. The > validator ties to > > only one form per action and since DispatchAction is still considered a > > single action (with different delegated methods), then you are > still bound > > to use only one set of validation rules for that form. > > > > Option 1 > > > > Use DispatchAction and implement your own validate() > method for that > > form > > > > Option 2 > > > > Split your operations into different actions using the same form, > > define different rules in the validation.xml and have your form extend > > ValidatorActionForm like Peter suggested > > > > > > > > > > > > Peter Onthrops <[EMAIL PROTECTED]> on 06/07/2002 02:34:40 PM > > > > Please respond to "Struts Users Mailing List" > > <[EMAIL PROTECTED]> > > > > To: Struts Users Mailing List <[EMAIL PROTECTED]> > > cc: > > Subject: Re: Struts Validator > > > > > > > > I think what you are looking for is handled by configuring > validation.xml > > in this way: > > <formset> > > <form name="action1"> (maps to action path) > > <field property="field1" .... > > <field property="field2" .... > > <field property="field3" .... > > </form> > > > > <form name="action2"> > > <field property="field1" .... > > </form> > > > > </formset> > > > > > > Your Form bean should extend ValidatorActionForm. The Validator > will only > > validate fields configured for the given action. Hope this helps. > > > > P. > > > > > > > > Robert Taylor <[EMAIL PROTECTED]> wrote: I want to leverage the > > declarative validation functionality offered by the > > Struts Validator package, but I have some reservations about > how it works. > > In my particular configuration, my application will use > DispatchActions to > > process common events. > > In many cases I will use one ActionForm for all events being > > processed by a > > particular ActionForm. Since I won't be validating all fields in > > all cases, > > I want to only validate certain fields for a particular action > > mapping. The > > only way I can tell how to do this is to use the page data member of > > ValidatorActionForm to identify those fields that need be validated. > > > > The problem I see with this, is ... > > - for mapping A, I may want to validate field1, field2, and field3, and > > - mapping B, I only want to validate field1, but > > - mapping C, I want to validate field1 and field3. > > > > Is this possible to do using the validation.xml file. That is, > can you do > > something like the following: > > > > ... > > ... > > ... > > > > where 1 = mapping for A, > > 2 = mapping for B, > > 3 = mapping for C > > > > If not, how is this possible? Is there a validator DTD I can reference? > > > > > > robert > > > > > > -- > > To unsubscribe, e-mail: > > For additional commands, e-mail: > > > > > > > > --------------------------------- > > Do You Yahoo!? > > Sign-up for Video Highlights of 2002 FIFA World Cup > > > > > > > > > > > > ********************************************************************** > > Please Note: > > The information in this E-mail message, and any files transmitted > > with it, is confidential and may be legally privileged. It is > > intended only for the use of the individual(s) named above. If you > > are the intended recipient, be aware that your use of any confidential > > or personal information may be restricted by state and federal > > privacy laws. If you, the reader of this message, are not the > > intended recipient, you are hereby notified that you should not > > further disseminate, distribute, or forward this E-mail message. > > If you have received this E-mail in error, please notify the sender > > and delete the material from any computer. Thank you. > > ********************************************************************** > > > > > > > > > > -- > > 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]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

