You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chetan Pandey <cp...@BLUEsingapore.com> on 2006/08/23 05:49:49 UTC
Form Validation
Hi All:
I have one Dispatch Action class with two methods 'create' and 'edit'.
Before Form is sent over it has to be validated.
I have the following in struts-config.xml
<action path="/manageProperty"
type="com.BLUE.lms.actions.property.ManageProperty"
parameter="function"
name="propertyForm"
scope="session"
validate="true"
input="property.create.page" >
<forward name="message" path="lms.message.display.page" />
</action>
But the thing is Line
input="property.create.page"
makes validation possible for Creation.
However I need to make Validation possible for
input="property.edit.page" also.
Is their a way to specify multiple inputs.
So that Validation will work for edit/create not just create.
Thanks.
Chetan
Re: Form Validation
Posted by Scott Van Wart <sc...@indosoft.com>.
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