You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mike Williams <mi...@cortexebusiness.com.au> on 2001/06/14 06:42:46 UTC

performing extra ActionForm validation within an Action

I'm thinking that it will probably be necessary for me to perform
validation of input forms in two steps:

  (1) I can do basic syntactic validation of the input fields within the
      ActionForm.validate() method, e.g. Is "amount" a number?  

  (2) More serious validation may need database connectivity, etc. e.g. Are
      there "amount" products in-stock?  This kind of validation code
      shouldn't really be in the ActionForm, should it?

Does that seem reasonable so far?  

Okay, assume that I have an "input" page defined in my action-mapping, for
use when step (1) validation fails. e.g.

    <action path="/save"
            type="xyz.action.widget.SaveAction"
            name="widgetForm"
            input="/widget/edit.jsp">
        <forward name="okay" path="/widget/main.jsp"/>
    </action>

How about if I detect an input error during step (2) validation, within the
Action?  Is it valid to do the following?

  return new ActionForward( mapping.getInput() )

Or, is it better to explicitly add another <forward>?

-- 
Mike


Re: performing extra ActionForm validation within an Action

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 14 Jun 2001, Mike Williams wrote:

> I'm thinking that it will probably be necessary for me to perform
> validation of input forms in two steps:
> 
>   (1) I can do basic syntactic validation of the input fields within the
>       ActionForm.validate() method, e.g. Is "amount" a number?  
> 
>   (2) More serious validation may need database connectivity, etc. e.g. Are
>       there "amount" products in-stock?  This kind of validation code
>       shouldn't really be in the ActionForm, should it?
> 
> Does that seem reasonable so far?  
> 
> Okay, assume that I have an "input" page defined in my action-mapping, for
> use when step (1) validation fails. e.g.
> 
>     <action path="/save"
>             type="xyz.action.widget.SaveAction"
>             name="widgetForm"
>             input="/widget/edit.jsp">
>         <forward name="okay" path="/widget/main.jsp"/>
>     </action>
> 
> How about if I detect an input error during step (2) validation, within the
> Action?  Is it valid to do the following?
> 
>   return new ActionForward( mapping.getInput() )
> 

That's what the example app does, for instance, on a login failure.  The
form bean can detect simple stuff like a missing username or password, but
it's the action that detects a failure requiring access to the database.

Using the value of mapping.getInput() to create your forward costs you an
object create (pretty small with modern VMs), but saves you having to
update two values in the configuration file if the name of the input page
ever changes (the "input" attribute of the action, and the new logical
forward you would create instead).

> Or, is it better to explicitly add another <forward>?
> 
> -- 
> Mike
> 
> 

Craig