struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <jakartau...@yahoo.com>
Subject Re: Two Submit Buttons with same Name, validation using ValidatorForm
Date Wed, 05 May 2004 12:23:25 GMT
I think the validation you're looking for is beyond the scope of the
validate() method.  The Struts form validation should concentrate on
syntactic validation, such as making sure a zip code field has the right
number of digits, a int field contains valid numeric data, a required field
was filled in, or a date field contains data in the correct format.
Take a look at struts-example.war.  The validate() method of RegistrationForm
checks that the given passwords match, but the check to see if the password
is valid is done in an Action class.

--- Eric Noel <ericnoel@mylife.ph> wrote:
> How do i validate in my ValidatorForm when in my html i have two submit 
> buttons having same name = "btn".
> 
> ## I have this idea of a login form with two submit buttons (ie., sign 
> in, passwd change) having same name "btn":
> 
> <html:errors />
> <html:form action="Login">
>        <table>
>          <tr>
>              <td><bean:message key="signinForm.loginname"/></td>
>              <td><html:text property="loginName"/> </td>
>              </tr>
>          <tr>
>              <td><bean:message key="signinForm.password"/></td>
>              <td><html:password property="loginPassword"/> </td>
>              </tr>
>          <tr>
>              <td><bean:message key="signinForm.newpassword"/></td>
>              <td><html:password property="loginNewPassword"/> </td>
>              </tr>
>          <tr>
>              <td><bean:message key="signinForm.confirmpassword"/></td>
>              <td><html:password property="loginConfirmPassword"/> </td>
>              </tr>
>          <tr>
>            <td >
>              <html:submit property="btn">
>                 <bean:message key="signinForm.signin"/>
>              </html:submit>
> 
>              <html:submit property="btn">
>                 <bean:message key="signinForm.pwdchg"/>
>              </html:submit>
>            </td>
>          </tr>
>        </table>
> </html:form>
> 
> ## On my LoginAction i used LookupDispatchAction
> ...<snipped>
> 
> protected Map getKeyMethodMap() {
>          Map map = new HashMap();
>          map.put("signinForm.signin", "signin");
>          map.put("siginForm.pwdchg", "pwdchg");
>          return map;
> }
> public ActionForward signin(
>   	    	LoginForm loginForm = (LoginForm)form;
>         	    	loginName = loginForm.getLoginName();
>         	    	loginPassword = loginForm.getLoginPassword();
>         	    	loginNewPassword = loginForm.getLoginNewPassword();
> 
> public ActionForward pwdchg(
>   	    	LoginForm loginForm = (LoginForm)form;
>         	    	loginName = loginForm.getLoginName();
>         	    	loginPassword = loginForm.getLoginPassword();
>         	    	loginNewPassword = loginForm.getLoginNewPassword();
> 
> 
> ## The question is how do i validate the fields in my ActionForm (ie.g 
> ValidatorForm). E.g if the password change button was clicked check if 
> loginNewPassword and loginChangePassword exists, etc. If sign in button 
> was clicked check if loginName exists, etc.
> 
> ## my ValidatorForm code below, but it validates for both buttons :
> ..<snipped>
> public ActionErrors validate(ActionMapping mapping,
> 			HttpServletRequest request) {
> 
> 		ActionErrors errors = super.validate(mapping, request);
> 		if (errors == null) errors = new ActionErrors();
> 		
> 		if ( (loginNewPassword == null ) || (loginNewPassword.length() == 0) 
> || (loginNewPassword.equals(""))) {
> 			errors.add("loginNewPassword",
> 					new ActionError("errors.login.newpassword.required"));
> 		}
> 		return errors;
>    	}
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

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


Mime
View raw message