craigmcc 2002/07/18 19:44:06 Modified: src/example/org/apache/struts/webapp/example RegistrationForm.java web/example registration.jsp web/example/WEB-INF validation.xml Log: Use validator framework on the registration page also. Revision Changes Path 1.4 +12 -31 jakarta-struts/src/example/org/apache/struts/webapp/example/RegistrationForm.java Index: RegistrationForm.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/RegistrationForm.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RegistrationForm.java 5 Mar 2002 04:23:56 -0000 1.3 +++ RegistrationForm.java 19 Jul 2002 02:44:06 -0000 1.4 @@ -68,6 +68,7 @@ import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; +import org.apache.struts.validator.ValidatorForm; /** @@ -93,7 +94,7 @@ * @version $Revision$ $Date$ */ -public final class RegistrationForm extends ActionForm { +public final class RegistrationForm extends ValidatorForm { // ----------------------------------------------------- Instance Variables @@ -334,34 +335,14 @@ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { - ActionErrors errors = new ActionErrors(); - if ((username == null) || (username.length() < 1)) - errors.add("username", - new ActionError("error.username.required")); - if (!password.equals(password2)) + // Perform validator framework validations + ActionErrors errors = super.validate(mapping, request); + + // Only need crossfield validations here + if (!password.equals(password2)) { errors.add("password2", new ActionError("error.password.match")); - if ((fromAddress == null) || (fromAddress.length() < 1)) - errors.add("fromAddress", - new ActionError("error.fromAddress.required")); - else { - int atSign = fromAddress.indexOf("@"); - if ((atSign < 1) || (atSign >= (fromAddress.length() - 1))) - errors.add("fromAddress", - new ActionError("error.fromAddress.format", - fromAddress)); - } - if ((fullName == null) || (fullName.length() < 1)) - errors.add("fullName", - new ActionError("error.fullName.required")); - if ((replyToAddress != null) && (replyToAddress.length() > 0)) { - int atSign = replyToAddress.indexOf("@"); - if ((atSign < 1) || (atSign >= (replyToAddress.length() - 1))) - errors.add("replyToAddress", - new ActionError("error.replyToAddress.format", - replyToAddress)); - } - + } return errors; } 1.23 +7 -1 jakarta-struts/web/example/registration.jsp Index: registration.jsp =================================================================== RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- registration.jsp 14 Jul 2002 01:35:18 -0000 1.22 +++ registration.jsp 19 Jul 2002 02:44:06 -0000 1.23 @@ -24,7 +24,8 @@ <html:errors/> -<html:form action="/saveRegistration"> +<html:form action="/saveRegistration" + onsubmit="return validateLogonForm(this);"> <html:hidden property="action"/> <table border="0" width="100%"> @@ -174,6 +175,11 @@ </logic:equal> + +<html:javascript formName="registrationForm" + dynamicJavascript="true" + staticJavascript="false"/> +<script language="Javascript1.1" src="staticJavascript.jsp"></script> </body> </html:html> 1.3 +26 -1 jakarta-struts/web/example/WEB-INF/validation.xml Index: validation.xml =================================================================== RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/validation.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- validation.xml 14 Jul 2002 01:38:31 -0000 1.2 +++ validation.xml 19 Jul 2002 02:44:06 -0000 1.3 @@ -51,6 +51,31 @@ </form> + <form name="registrationForm"> + + <field property="fromAddress" + depends="required,email"> + <arg0 key="prompt.fromAddress"/> + </field> + + <field property="fullName" + depends="required"> + <arg0 key="prompt.fullName"/> + </field> + + <field property="replyToAddress" + depends="email"> + <arg0 key="prompt.replyToAddress"/> + </field> + + <field property="username" + depends="required"> + <arg0 key="prompt.username"/> + </field> + + </form> + + </formset>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>