struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Lipscombe" <adam.lipsco...@expensys.com>
Subject RE: Newbie question: How to implement conditional validation in an ActionForm?
Date Thu, 13 May 2004 16:46:31 GMT
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:john@jmsd.co.uk] 
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  -  john@jmsd.co.uk
==============================================

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



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


Mime
View raw message