We have a similar situation using action classes based on the
LookupDispatchAction.  We have not implemented this yet, but our approach
will be to have two action mappings.  We'll do the following:

In the form class, we'll override validate() to do three things:
1)  call super.validate().
2)  If ActionErrors are returned, we'll change the dispatchAction (used to
map to the method) in the form/request, adding something like
"ValidationFailed" to the existing value.
3)  Return the ActionErrors.

The first mapping will have validate="true", so the server-side validation
will be used.  The input attribute will be a forward to the second mapping,
which will look exactly like the first, except that validate will be set to
"false".

The second mapping will look like the first, but validate will be "false".
It will be responsible for forwarding back to the edit page from which the
validation error originated.

The ActionClass (actually the super class that implements some default
behaviors) will also implement methods to support the possible validation
failure methods.  These methods will simply forward to the appropriate
mapping, insuring that the form is in the request - if applicable, any
other needed objects would be addressed here as well.  For example
(simple):

public ActionForward saveNewValidationFailed ActionMapping mapping,
ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
throws IOException,
                  ServletException {
      request.setAttribute(EDIT_FORM_NAME, form);
      return mapping.findForward(FORWARD_ADD)
}

public ActionForward saveUpdateValidationFailed ActionMapping mapping,
ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
throws IOException,
                  ServletException {
      request.setAttribute(EDIT_FORM_NAME, form);
      return mapping.findForward(FORWARD_EDIT)
}

I can't guarantee that this is the right way, or even that it would work
since we have yet to implement it, but it sounds reasonable to our team.
Nick



                                                                                       
                                                
                      "thomas                                                          
                                                
                      Sontheimer"              To:       "'Struts Users Mailing List'" 
<[EMAIL PROTECTED]>                
                      <thomas.sontheime        cc:                                     
                                                
                      [EMAIL PROTECTED]>              Subject:  RE : RE : Validator 
and Dispatch Actions                                      
                                                                                       
                                                
                      08/26/2003 04:37                                                 
                                                
                      AM                                                               
                                                
                      Please respond to                                                
                                                
                      "Struts Users                                                    
                                                
                      Mailing List"                                                    
                                                
                                                                                       
                                                
                                                                                       
                                                




if you want to use different validation rules with the validator you
have to declare different action elements in your struts-config.xml file
(using the same action class if you want).

another means is to validate your form in the methods of your action
class as propose Koni in the mail sent on the list Monday, August 25,
2003 8:04 PM:

struts-config.xml:

        <action    path="/logon/action/logon"
                   type="test.web.struts.action.logon.LogonAction"
                   name="logonForm"
                  scope="request"        <-- !!!
               validate="false"          <-- !!!
                  input="/WEB-INF/jsp/logon/logon.jsp">
             <forward   name="success"   path="/index.jsp"/>
        </action>

LogonAction.java:

   ActionErrors errors = new ActionErrors();
   errors = form.validate(mapping, request);

   // Report any errors we have discovered back to the original form
   if (!errors.isEmpty())
   {
       saveErrors(request, errors);
       return  new ActionForward(mapping.getInput());
   }

thomas

> -----Original Message-----
> From: manglu [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 26, 2003 5:44 PM
> To: [EMAIL PROTECTED]
> Subject: Re: RE : Validator and Dispatch Actions
>
>
> Thomas,
>
> How do i have 3 actions here?
>
> I have only one action with three methods each working on
> SEARCH, CREATE
> and EDIT.(which is why i use the dispatch Action)
>
> Appreciate any other thoughts.
>
> TIA,
> Manglu
>
>
>
> thomas Sontheimer wrote:
> > you have to use (Dyna)ValitatorActionForm instead of
> > (Dyna)ValidatorForm. Then in your validation.xml file for each new
> > rule you specify you have to replace the name of the form
> by the name
> > of the action using the form. And the rule will be applied
> to the form
> > only if it's called from the action you gave the name.
> > In your case you have to specify 1 form, 3 actions and 3 rules.
> >
> > thomas
> >
> >
> >>-----Original Message-----
> >>From: manglu [mailto:[EMAIL PROTECTED]
> >>Sent: Tuesday, August 26, 2003 1:33 AM
> >>To: [EMAIL PROTECTED]
> >>Subject: Validator and Dispatch Actions
> >>
> >>
> >>Hi,
> >>
> >>I want to use the Struts Validator to do validation.
> >>
> >>
> >>The Same action form is used for SEARCH, CREATE and EDIT.
> >>
> >>The validation rules for each of them is different( from the
> >>other two)
> >>
> >>How do i go about defining such a config in the validation
> >>config file.
> >>
> >>Appreciate any help.
> >>TIA
> >>Manglu
> >>
> >>
> >>
> >>------------------------------------------------------------
> ---------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to