A couple of observations:

1) Struts comes with "cancel" processing, if you use the <html:cancel> tag
then the validation in the ActionForm should not be called and Strust should
set attribute with name Globals.CANCEL_KEY  in the request to "true".

2) If you use validator, then it can handle different page validations for
the same form.

Niall

----- Original Message ----- 
From: "Adam Lipscombe" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Thursday, May 13, 2004 5:46 PM
Subject: RE: Newbie question: How to implement conditional validation in an
ActionForm?


Thanks for the help. I am doing the validation in the ActionForm class, in
which the validate() method is like this:


  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest)
  {
    assert(null != pageNumber); // Page number should always be set

    ActionErrors errors = null;

    if ("1".equals(pageNumber))
    {
      errors = validatePage1(actionMapping, httpServletRequest);
    }
    else if ("2".equals(pageNumber))
    {
      errors = validatePage2(actionMapping, httpServletRequest);
    }
    else if ("3".equals(pageNumber))
    {
      errors = validatePage3(actionMapping, httpServletRequest);
    }
    else
    {
      errors = new ActionErrors();
      errors.add(ActionErrors.GLOBAL_ERROR,
                   new ActionError("errors.unexpectedError"));
    }

    return errors;
  }



Is there any way to recognise that the cancel button has been pressed wothin
the validate method?
Or should I move the validation to the Action classes?



TIA - Adam



-----Original Message-----
From: John Moore [mailto:[EMAIL PROTECTED]
Sent: 13 May 2004 17:33
To: Struts Users Mailing List
Subject: Re: Newbie question: How to implement conditional validation in an
ActionForm?


Adam Lipscombe wrote:

>
>I have implemented  a wizard framework. Each JSP page uses the same
>ActionForm, passing a hidden property "pageNumber" to control which
>validation  is applied. As the wizard progresses the ActionForm data is
>built up. This works well as long as the user presses "next" or
>finish".
>
>However if the user presses "cancel"  the ActionForm.validate() method
>is called and the wizard page is re-displayed with any errors. If the
>cancel is pressed I just want to exit the wizard without calling the
>ActionForm.validate() method.Or at least be able to detect that the
>cancel button was pressed within the ActionForm.validate() method.
>
>
>Apologies if this is obvious. Any ideas?
>
>
>
>
Where are you doing your validation? I've done something similar (a
wizard) and I'm doing the validation within the Action class. I test for
which submit button has been pressed (i.e., what the text of the
'submit' parameter is) and act accordingly. You could certainly test for
Cancel there and bypass the validation.

John

-- 
==============================================
John Moore  -  Norwich, UK  -  [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