struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Van Wart <sc...@indosoft.com>
Subject Re: Form Validation
Date Wed, 23 Aug 2006 21:51:24 GMT
Chetan Pandey wrote:
> Is their a way to specify multiple inputs.
>   

Nope.  A wise man once told me that validate="true" is there only for 
convenience.  So the workaround is to do something like 
'validate="false"', omit the input= tag, and add forwards like,

<action...>
  <forward name="add" path="page.add" />
  <forward name="edit" path="page.edit" />
</action>

public void create( ActionMapping mapping, ... ) {

  ActionErrors errors = form.validate( mapping, request );
  if ( errors == null ) {
    errors = new ActionErrors();
  } else if ( !errors.isEmpty() ) {
    saveErrors( errors );
    return mapping.findForward( "add" );
  }

  // Do some stuff

  // ... aaaaand success!
  myForm.setId( someObject.getId() );
  return mapping.findForward( "edit" );

}

So if it passes validation and everything checks out okay, it goes to 
the edit page to the newly added record.  Otherwise it goes back to 
add.  You can do the same thing for delete (ie: if you were editing a 
record, but suddenly lose the state of the record you're editing because 
the user is mucking about).

This gives you more power over when and how to do validation, and what 
to do on pass/fail (sometimes you might have to repopulate a few of the 
ActionForm's values--which is something else you can't do with the 
validate="true" shortcut).

- Scott


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


Mime
View raw message