struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Noel <ericn...@mylife.ph>
Subject Two Submit Buttons with same Name, validation using ValidatorForm
Date Wed, 05 May 2004 03:24:42 GMT
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


Mime
View raw message