Validator Framework Questions
Hello! Reading a Struts book I wanted to give the validator framework a whirl. Since it's poorly described in the book I checked out Struts website. I wonder if when we speak about automatic form validation, then if do we mean the validator from the website http://home.earthlink.net/~dwinterfeldt or has another validator been integrated into Struts. How doI setup an automatic form validation? I've build a form with 3 fields called field1, field2, field3 and a submit button. I've defined the validation rules in the validation.xml file, but this thing just doesn't work. Below my setup. my validation.xml looks like this: form-validation formset form name=postTestForm field property=field1 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.titlelabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value5/var-value /var /field field property=field2 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.introlabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value2048/var-value /var /field field property=field3 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.bodylabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value10/var-value /var /field /form /formset /form-validation my struts-config.xml lookis like this: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE struts-config PUBLIC -//Apache Software Foundation//DTD Struts Configuration 1.1//EN http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd; struts-config form-beans form-bean name=postTestForm type=org.apache.struts.validator.DynaActionForm form-property name=field1 type=java.lang.String initial=/ form-property name=field2 type=java.lang.String initial=/ form-property name=field3 type=java.lang.String initial=/ /form-bean /form-beans global-forwards forward name=system.error path=/WEB-INF/jsp/systemError.jsp/ forward name=default.action path=/execute/homePageSetuo/ /global-forwards action-mappings action path=/homePageSetup type=com.mycompany.HomePageSetupAction unknown=true forward name=homepage.success path=/WEB-INF/jsp/homePage.jsp/ /action action path=/postTestSetup type=com.mycompany.PostTestSetupAction name=postTestForm scope=request validate=false forward name=posttest.success path=/WEB-INF/jsp/postTest.jsp / /action action path=/postTest input=/WEB-INF/jsp/postTest.jsp type=com.mycompany.PostTest name=postTestForm scope=request validate=true forward name=posttest.success path=/execute/homePageSetup/ /action /action-mappings plug-in className=org.apache.struts.validator.ValidatorPlugIn set-property property=pathnames value=/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml/ /plug-in /struts-config Thanks in advance for you help! Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validator Framework Questions
change your strut config to use org.apache.struts.validator.DynaValidatorForm -Dan - Original Message - From: Thomas Miskiewicz [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, June 15, 2003 9:42 AM Subject: Validator Framework Questions Hello! Reading a Struts book I wanted to give the validator framework a whirl. Since it's poorly described in the book I checked out Struts website. I wonder if when we speak about automatic form validation, then if do we mean the validator from the website http://home.earthlink.net/~dwinterfeldt or has another validator been integrated into Struts. How doI setup an automatic form validation? I've build a form with 3 fields called field1, field2, field3 and a submit button. I've defined the validation rules in the validation.xml file, but this thing just doesn't work. Below my setup. my validation.xml looks like this: form-validation formset form name=postTestForm field property=field1 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.titlelabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value5/var-value /var /field field property=field2 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.introlabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value2048/var-value /var /field field property=field3 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.bodylabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value10/var-value /var /field /form /formset /form-validation my struts-config.xml lookis like this: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE struts-config PUBLIC -//Apache Software Foundation//DTD Struts Configuration 1.1//EN http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd; struts-config form-beans form-bean name=postTestForm type=org.apache.struts.validator.DynaActionForm form-property name=field1 type=java.lang.String initial=/ form-property name=field2 type=java.lang.String initial=/ form-property name=field3 type=java.lang.String initial=/ /form-bean /form-beans global-forwards forward name=system.error path=/WEB-INF/jsp/systemError.jsp/ forward name=default.action path=/execute/homePageSetuo/ /global-forwards action-mappings action path=/homePageSetup type=com.mycompany.HomePageSetupAction unknown=true forward name=homepage.success path=/WEB-INF/jsp/homePage.jsp/ /action action path=/postTestSetup type=com.mycompany.PostTestSetupAction name=postTestForm scope=request validate=false forward name=posttest.success path=/WEB-INF/jsp/postTest.jsp / /action action path=/postTest input=/WEB-INF/jsp/postTest.jsp type=com.mycompany.PostTest name=postTestForm scope=request validate=true forward name=posttest.success path=/execute/homePageSetup/ /action /action-mappings plug-in className=org.apache.struts.validator.ValidatorPlugIn set-property property=pathnames value=/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml/ /plug-in /struts-config Thanks in advance for you help! Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validator Framework Questions
Dan, change your strut config to use org.apache.struts.validator.DynaValidatorForm That helped. Could you or someone please else answer my questions regarding the validator framework itself? Is it part of Struts framework or not (I'm using the 1.1 rc2). What steps are required to setup and use it? Where do I find more info about it. Thanks Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validator Framework Questions
I think it is necessary to include a input property in the action element, so if the data is invalid the controller can recall the form file (or tiles action). action path=/nameOfAction name=nameOfForm type=package.package.class validate=true input=/file.jsp OR .tiles.action forward name=key path=file.jsp OR .tiles.action/ /action Pedro Salgado On 15/06/2003 17:59, Dan Tran [EMAIL PROTECTED] wrote: change your strut config to use org.apache.struts.validator.DynaValidatorForm -Dan - Original Message - From: Thomas Miskiewicz [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, June 15, 2003 9:42 AM Subject: Validator Framework Questions Hello! Reading a Struts book I wanted to give the validator framework a whirl. Since it's poorly described in the book I checked out Struts website. I wonder if when we speak about automatic form validation, then if do we mean the validator from the website http://home.earthlink.net/~dwinterfeldt or has another validator been integrated into Struts. How doI setup an automatic form validation? I've build a form with 3 fields called field1, field2, field3 and a submit button. I've defined the validation rules in the validation.xml file, but this thing just doesn't work. Below my setup. my validation.xml looks like this: form-validation formset form name=postTestForm field property=field1 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.titlelabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value5/var-value /var /field field property=field2 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.introlabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value2048/var-value /var /field field property=field3 depends=required,maxlength msg name=required key=error.posttest.field.null/ msg name=maxlength key=error.posttest.field.length/ arg0 key=myapp.posttest.form.bodylabel/ arg1 name=maxlength key=${var:maxlength} resource=false/ var var-namemaxlength/var-name var-value10/var-value /var /field /form /formset /form-validation my struts-config.xml lookis like this: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE struts-config PUBLIC -//Apache Software Foundation//DTD Struts Configuration 1.1//EN http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd; struts-config form-beans form-bean name=postTestForm type=org.apache.struts.validator.DynaActionForm form-property name=field1 type=java.lang.String initial=/ form-property name=field2 type=java.lang.String initial=/ form-property name=field3 type=java.lang.String initial=/ /form-bean /form-beans global-forwards forward name=system.error path=/WEB-INF/jsp/systemError.jsp/ forward name=default.action path=/execute/homePageSetuo/ /global-forwards action-mappings action path=/homePageSetup type=com.mycompany.HomePageSetupAction unknown=true forward name=homepage.success path=/WEB-INF/jsp/homePage.jsp/ /action action path=/postTestSetup type=com.mycompany.PostTestSetupAction name=postTestForm scope=request validate=false forward name=posttest.success path=/WEB-INF/jsp/postTest.jsp / /action action path=/postTest input=/WEB-INF/jsp/postTest.jsp type=com.mycompany.PostTest name=postTestForm scope=request validate=true forward name=posttest.success path=/execute/homePageSetup/ /action /action-mappings plug-in className=org.apache.struts.validator.ValidatorPlugIn set-property property=pathnames value=/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml/ /plug-in /struts-config Thanks in advance for you help! Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED
Re: Validator Framework Questions
The Validator framework (commons-validator) comes with the struts distribution. To install it you will need: jakarta-oro, commons-beanutils, commons-logging, commons-collections, commons-digester. Put these files (.jar) on your WEB-INF/lib (if you already installed struts it will only be missing the jakarta-oro.jar and commons-validator.jar). Configure your validation-rules.xml , validation.xml (better have an example to start with... And download the dtds of these files... You may need them.) and configure your struts-config.xml (the one had you seemed ok). Place the dtd files on a webapp directory (for example: /WEB-INF/dtd). Change the validation-rules.xml and validation.xml DOCTYPE element (in case you are developing without an internet connection, at the server startup it tries to validate the 2 files - tries to retrive http://jakarta.apache.org.../file.dtd - if the container doesnt find these files an error occurs )... Example: for validation.xml ?xml version=1.0? !DOCTYPE form-validation SYSTEM /Library/Tomcat/Home/webapps/mywebapp/WEB-INF/dtds/validation_1_1.dtd form-validation ... /form-validation You also have to include some properties on your webapp message resources: errors.required={0} is required. errors.minlength={0} can not be less than {1} characters. errors.maxlength={0} can not be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be a byte. errors.short={0} must be a short. errors.integer={0} must be an integer. errors.long={0} must be a long. errors.float={0} must be a float. errors.double={0} must be a double. errors.date={0} is not a date. errors.range={0} is not in the range {1} through {2}. errors.creditcard={0} is an invalid credit card number. errors.email={0} is an invalid e-mail address. These were all the steps I had to make... Good luck :) Pedro Salgado On 15/06/2003 18:09, Thomas Miskiewicz [EMAIL PROTECTED] wrote: Dan, change your strut config to use org.apache.struts.validator.DynaValidatorForm That helped. Could you or someone please else answer my questions regarding the validator framework itself? Is it part of Struts framework or not (I'm using the 1.1 rc2). What steps are required to setup and use it? Where do I find more info about it. Thanks Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validator Framework Questions
Thomas, I have seen may developers struggling with Struts Validation (IMHO, it is a GIFT to us). The best way is to read some good book like the one from Chuck Cavaness. I read it once and my validation never fail me. Or you can view his article http://jakarta.apache.org/struts/resources/articles.html -Dan - Original Message - From: Thomas Miskiewicz [EMAIL PROTECTED] Newsgroups: Struts Sent: Sunday, June 15, 2003 10:09 AM Subject: Re: Validator Framework Questions Dan, change your strut config to use org.apache.struts.validator.DynaValidatorForm That helped. Could you or someone please else answer my questions regarding the validator framework itself? Is it part of Struts framework or not (I'm using the 1.1 rc2). What steps are required to setup and use it? Where do I find more info about it. Thanks Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]