Writing Javascript for Validators
Hello All, I've written a new plugable validator rule, and now I'd like to write some javascript for it. Looking at the existing javascript for other validators, I see they all make a call like this: oRequired = new required(); which (in this case) gets all the required fields. I'm not sure what generates this method, but I can see it in my jsp when i put in html:javascript. my new rule is called futuredate. I don't know what sort of method I should call that will be like required(); but give me all the fields marked with furuterdate. How do I do this? Cheers __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing Javascript for Validators
Matt E wrote: Hello All, I've written a new plugable validator rule, and now I'd like to write some javascript for it. Looking at the existing javascript for other validators, I see they all make a call like this: oRequired = new required(); which (in this case) gets all the required fields. I'm not sure what generates this method, but I can see it in my jsp when i put in html:javascript. my new rule is called futuredate. I don't know what sort of method I should call that will be like required(); but give me all the fields marked with furuterdate. How do I do this? Warning, I haven't done this before, but need to : The validator-rules.xml and validator.xml file for your project have the same format. In --your-- validator.xml you can enter: form-validation global validator name=futuredate classname=com.matte.futuredate.validator.FieldChecks method=validateFutureDate methodParams=java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest msg=errors.required javascript![CDATA[ function validateFutureDate(form) { ...Your code } ]] /javascript /validator /global I believe that all required I don't believe you need to extend the StrutsJavaScriptTag. Is that helpful at all ? Cheer -- Robert Leland [EMAIL PROTECTED] -- Java, J2EE, Struts, Web Application Development 804 N. Kenmore Street +01-703-525-3580 Arlington VA 22201 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing Javascript for Validators
Robert, Warning, I haven't done this before, but need to : The validator-rules.xml and validator.xml file for your project have the same format. In --your-- validator.xml you can enter: form-validation global validator name=futuredate classname=com.matte.futuredate.validator.FieldChecks method=validateFutureDate methodParams=java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest msg=errors.required javascript![CDATA[ function validateFutureDate(form) { ...Your code } ]] /javascript /validator /global My question is this. In that Javascript code, I need to validate the fields. How do I know what fields need to validated? The javascript methods provided by Struts for the other validators seem to call a method that builds an array of all the fields in the form to check, and then do a loop over that array. (for example, the required validator makes a call to a method called required()). My question is what call should I be making? I don't know how the required() method is being generated (it isn't in the validation-rules.xml file, but it appears in the code included by html:javascript. I'm going to need something like a futuredate() method that builds this array, but I don't know where I need to write it (or how I tell struts to build it for me). Does this make sense? Cheers __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Writing Javascript for Validators
Matt, the required javascript method is generated in the org.apache.struts.taglob.JavascriptValidatorTag class. The doStartTag method (at line 305) builds the required javascript method (or any other method that the form needs). Grab a copy of the Struts source and check it out... should be very helpful. Cheers, Dan -Original Message- From: Matt E [mailto:[EMAIL PROTECTED] Sent: Tuesday, 19 August 2003 2:43 PM To: Struts Users Mailing List Subject: Re: Writing Javascript for Validators Robert, Warning, I haven't done this before, but need to : The validator-rules.xml and validator.xml file for your project have the same format. In --your-- validator.xml you can enter: form-validation global validator name=futuredate classname=com.matte.futuredate.validator.FieldChecks method=validateFutureDate methodParams=java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest msg=errors.required javascript![CDATA[ function validateFutureDate(form) { ...Your code } ]] /javascript /validator /global My question is this. In that Javascript code, I need to validate the fields. How do I know what fields need to validated? The javascript methods provided by Struts for the other validators seem to call a method that builds an array of all the fields in the form to check, and then do a loop over that array. (for example, the required validator makes a call to a method called required()). My question is what call should I be making? I don't know how the required() method is being generated (it isn't in the validation-rules.xml file, but it appears in the code included by html:javascript. I'm going to need something like a futuredate() method that builds this array, but I don't know where I need to write it (or how I tell struts to build it for me). Does this make sense? Cheers __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - 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]