struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Susan Bradeen" <Sus...@softlanding.com>
Subject DynaValidatorForm with validate()
Date Wed, 29 Jan 2003 19:43:37 GMT
Can you override (or supplement?) a DynaValidatorForm with a form bean, 
and use the validate() method along with the validations specified in the 
validation.xml? I can display my validation.xml errors, but not any from 
my validate() method. It appears to bypass it and go right to the 
'success' page. Seems like this should work, but obviously I am missing 
something. 

I have a DynaValidatorForm and a "form bean" and action mapping as 
follows:

<form-bean
  name="profileform"
  type="org.apache.struts.validator.DynaValidatorForm">
  <form-property
    name="userName"
    type="java.lang.String" />
  <form-property
    name="password"
    type="java.lang.String" />
  <form-property
    name="confirmPassword"
    type="java.lang.String" />
  ...
</form-bean>

public class ProfileForm extends DynaValidatorForm {
  public ProfileForm() {
    super();
  }
 
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 
{
    ActionErrors errors = super.validate(mapping, request);
    if (errors == null) {
       errors = new ActionErrors();
    }
 
    String pw = (String)this.get("password");
    String cpw = (String)this.get("confirmPassword");
 
    if (!(pw.equals(cpw))) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.validate.password"));
    }
 
    if (errors.isEmpty()) {return null;}
    return (errors);
  } 
}


<action
   path="/savenewprofile"
   type="com.etc.actions.RegisterPostAction"
   name="profileform"
   scope="request"
   input=".register"
   validate="true">
   <forward name="success" path=".login"/>
   <forward name="cancel" path=".main"/>
</action>


Any suggestions? 

Susan Bradeen
SoftLanding Systems, Inc
susanb@softlanding.com

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


Mime
View raw message