Thanks for responding Matt. The crux of the problem is that Struts is generating (as expected) a method based on the validation form name - which equates to my action mapping's path - but that the validateRequired.js seems (from a javascript alert) to be trying to call a method which uses the struts-config's form name.
See intermixed as well. Niall ----- Original Message ----- From: "Matt Bathje" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, November 11, 2004 8:02 PM Subject: Re: Does Javascript Validation work with mapping path as key? > Niall - some comments inline and other stuff below... > > Niall Pemberton wrote: > > I'm trying to get javascript validation working using the action mapping's > > path as the validation key with Struts 1.2.4. > > > > I don't usually use js (I'm trying to test something) but the generated > > javascript doesn't appear to work - from where I'm sitting it looks broken - > > can anyone confirm if they have it working or not? > > > > I have the following mapping in my struts config: > > > > <action path="/houseTypeAdd" type="....." > > name="myForm" scope="request" validate="true" input="housetype.add"> > > ... > > </action> > > > > And my jsp has the following form & javascript tags: > > > > <html:form action="houseTypeAdd" focus="housetype_code" > > onsubmit="return validateHouseTypeAdd(this);"> > > ... > > </html:form> > > <html:javascript formName="houseTypeAdd" bundle="niall-1"/> > > > > There are three fields defined as 'required' and it genertes a javascript > > function called houseTypeAdd_required () - however when I put an alert in > > the required.js script it seems to be trying to call function named after > > the form rather than the mapping (i.e. myForm_required()) - so its using the > > form name rather than the mappings path. > > I'm not sure what you are getting at here - from what I can tell from > the code you posted, the form name and mapping name are the same, so > either way it shouldn't make a difference (But see my comments below as > well...) OK form name is confusing - theres the name of the form in the struts-config and the name of the form in validation.xml. I'm validating using the mapping's path so the name of the form in the validation.xml is "houseTypeAdd" - and thats the name of the method being generated i.e. houseTypeAdd_required () - but the validateRequired.js script is trying to call a method using the struts-config form name - i..e. myForm_required() and so nothing is happening. > Where do you expect myForm to come from (or not come from?) > Its a regular struts ActionForm defined in my struts-config > What happens when the javascript validation kicks in? Javascript errors? > Java errors? Nothing? No javascript errors, I put the following alert in the validateRequired.js script: alert("validateRequired(form): about to call method: " + formName.value +"_required()"); ...and when I submit my form I see the alert, which pops up the following message "validateRequired(form): about to call method: myForm_required()" Then, I see the errors from the Server Side validation (rather than javascript). > > > > Can anyone see what I'm doing wrong or confirm it doesn't work? Below is > > relevant detail of the javascript being generated > > > > Thanks > > > > Niall > > > > function validateHouseTypeAdd(form) { > > if (bCancel) > > return true; > > else > > var formValidationResult; > > formValidationResult = validateRequired(form); > > return (formValidationResult == 1); > > } > > function houseTypeAdd_required () { > > this.a0 = new Array("housetype_code", "[Bundle 1] custom {0} is > > required.", new Function ("varName", " return this[varName];")); > > this.a1 = new Array("housetype_short_desc", "[Bundle 1] custom [Bundle 2] > > short-desc-msg is required.", new Function ("varName", " return > > this[varName];")); > > this.a2 = new Array("housetype_desc", "[Bundle 1] custom [Bundle 1] > > description-msg is required.", new Function ("varName", " return > > this[varName];")); > > } > > function validateRequired(form) { > > var isValid = true; > > var focusField = null; > > var i = 0; > > var fields = new Array(); > > var formName = form.getAttributeNode("name"); > > alert("validateRequired(form): about to call method: " + formName.value + > > "_required()"); > > oRequired = eval('new ' + formName.value + '_required()'); > > for (x in oRequired) { > > > 1.2.4 does indeed always use the form name instead of possibly using the > action mapping name, check out bugzilla report: > http://issues.apache.org/bugzilla/show_bug.cgi?id=29796 > for the bug and reasoning behind the patch. I did spend time looking at this bug and the fix before posting - but it didn't seem like the cause of the problem, since Struts was already using the Validator form name to generate the method and all the patch seemed to be doing was replacing any characters that javascript couldn't cope with. > I coded/tested the patch for that, and it worked fine for me then. I > also use it on some test sites, and it was working fine for me the last > time I used it there a week or so ago. Thats what surprised me and why I'm happy you replied, since as its obviously a fix for people using the mappings path as the validator form name. My first reaction was, this is broken - but then seeing that bugzilla saying you tested it made me think I must be doing something wrong. Plus there must be people using javascript validation, and ValidatorActionform or DynaValidatorActionForm and Strust 1.2.4. > Is it possible we can see the generated html form tag, as well as the > form bean definition and validator xml definition? I think it would help > in solving this. Also, a description of exactly what you are seeing > error wise (and even in your alert) would be helpful. Sure, the generated form html is... <form name="myForm" method="post" action="/plotsales/houseTypeAdd.do" onsubmit="return validateHouseTypeAdd(this);"> ... </form> Struts-config form bean is... <form-bean name="myForm" type="uk.co.plotsales.webapp.PlotsalesActionForm"> <form-property name="beans" type="java.util.ArrayList"/> </form-bean> Form validation.xml is... <form name="houseTypeAdd"> <field property="housetype_code" depends="required"> <msg name="required" key="error.missing"/> <msg name="requiredzzz" key="[Not Resource: Code is missing!!!!" resource="false"/> </field> <field property="housetype_short_desc" depends="required"> <msg name="required" key="error.missing" bundle="niall-1"/> <arg key="short.desc" bundle="niall-2" position="0"/> </field> <field property="housetype_desc" depends="required"> <msg name="required" key="error.missing" bundle="niall-1"/> <arg key="long.desc" position="0"/> </field> </form> > > Matt Niall --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]