You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andreas Wuest <An...@gmx.de> on 2003/11/15 14:36:50 UTC

struts 1.1 validation problem / question

Hi,

i have a small problem / question concerning the struts 1.1 validation.
i have a jsp form that has the following input fields : 

id
name
password
userAction

Depending on the userAction value (can be 'show' or 'save') i need to 
validate only the id (when userAction is 'show') or the name, password
and id (when the userAction is 'save').
i have one form that contains the 4 properties (with getters and setters)
and an action class that handles the show and the save action. 

the problem that i have is the validation. as far as i understand the 
docuemtneation it is not possible to validate a property only when
another property has a certain value. in other words it is not possible
to tell the validator to skip validation of a property when another property
has a certain value. 
or am i mistaken ?

how can i solve this problem ? do i need 2 forms and action to handle the
different userActions or is there another way ??

Thanks in advance,

 Andreas 


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


Re: struts 1.1 validation problem / question

Posted by Phil <pe...@letthemusicplay.de>.
Hi Andreas,

i think the best way is to write your own
validate() method in your action form. There you
can easily check the value of the userAction attribute
and depending on that the other attributes.

example:

public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
  ActionErrors errors = new ActionErrors();

  if (getName().length() < 1) {
   errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("form.error.name.required"));
  }

  return errors;
 }

HTH

Phil

----- Original Message -----
From: "Andreas Wuest" <An...@gmx.de>
To: <st...@jakarta.apache.org>
Sent: Saturday, November 15, 2003 2:36 PM
Subject: struts 1.1 validation problem / question


> Hi,
>
> i have a small problem / question concerning the struts 1.1 validation.
> i have a jsp form that has the following input fields :
>
> id
> name
> password
> userAction
>
> Depending on the userAction value (can be 'show' or 'save') i need to
> validate only the id (when userAction is 'show') or the name, password
> and id (when the userAction is 'save').
> i have one form that contains the 4 properties (with getters and setters)
> and an action class that handles the show and the save action.
>
> the problem that i have is the validation. as far as i understand the
> docuemtneation it is not possible to validate a property only when
> another property has a certain value. in other words it is not possible
> to tell the validator to skip validation of a property when another
property
> has a certain value.
> or am i mistaken ?
>
> how can i solve this problem ? do i need 2 forms and action to handle the
> different userActions or is there another way ??
>
> Thanks in advance,
>
>  Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Re: struts 1.1 validation problem / question

Posted by Andreas Wuest <An...@gmx.de>.
Hi Victor,

thanks for you reply.  the lookupdispatchaction does not really solve
my problem, since handling the different actions is not the problem.
the problems is the validation of the input fields for the different 
action. i need different validations depending on the value of the
userAction html form value.

thanks, 

 Andreas

On Sunday 16 November 2003 10:51, Victor wrote:
> Oi Andre,
>
> Tries to verify the LookupDispatchAction class, this
> class allows to manage diverse actions in simple
> Action and in this way you can better manage its
> validations with the Validator.
>
> Good code.
> Victor Amano Izawa
>
> ______________________________________________________________________
>
> Yahoo! Mail: 6MB, anti-spam e antivĂ­rus gratuito! Crie sua conta agora:
> http://mail.yahoo.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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


Re: struts 1.1 validation problem / question

Posted by Victor <vi...@yahoo.com.br>.
Oi Andre, 

Tries to verify the LookupDispatchAction class, this
class allows to manage diverse actions in simple
Action and in this way you can better manage its
validations with the Validator.

Good code.
Victor Amano Izawa

______________________________________________________________________

Yahoo! Mail: 6MB, anti-spam e antivĂ­rus gratuito! Crie sua conta agora:
http://mail.yahoo.com.br

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