I need to do some custom validation on my struts application. But when I run the jsp it does not validate. Moreover when I do view source, I don't see the name of method in the file either. I have the following code. I made a jar file with this class in it and the jar file is in tomcat lib dir.
validation.xml I have the following lines. <formset>
There is difference in method params for ActionMessages that you have mentioned in your validator-rules.xml, whereas its mentioned as ActionMessage in your validation class file. thats why the method is not being calles because it differ in its signature- in class and in validator-rule.xml file.
Garandi Garandi
Ranch Hand
Joined: Jan 07, 2003
Posts: 192
posted
0
Thank you Marc and Damanjit. I am planning to do server side as well as client side validation. But as far as my server side validation goes for now, I can see SOME of the log msgs printed. but page is forwarded as there is no error on the page.
In your validation.xml depends="jawadcontactInfoValidation"> doesn't match with validator name="contactInfoValidation" in validator-rules.xml file. and so validation is not being performed and also its better if you also check the method name in validator-rules.xml file with method name in your validation class file.
Hope this will fix the problem.
Garandi Garandi
Ranch Hand
Joined: Jan 07, 2003
Posts: 192
posted
0
Thank you Damanjit for your reply; server validation is working now, but I have problem with client validation.
This is valitator-rules.xml file
<validator name="contactInfoValidation" classname="com.mycom.sp.validation.SupportValidation" method="validateContactInfoField" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, javax.servlet.http.HttpServletRequest" msg="errors.required"> <javascript><![CDATA[ function myValidation(form) { alert("I am from custom validation"); return false; } ]]> </javascript> </validator>
Q1: Why alert does not pop up on the screen? Q2: Should I use jsFunction if yes, how? Thank you in advance Garandi
Damanjit Kaur
Ranch Hand
Joined: Oct 18, 2004
Posts: 346
posted
0
Hi,
You can specify javascript function or jsFunction both in validator-rule.xml file.
The code in your application also looks fine.
Have you specified the tag :
<html:javascript formName="logonForm"/> in your jsp file to enable the client side validation.
But the class specified in className doesn't come with jakarta-struts, I don't know where to find this file(I mean I searched the internet and couldn't find it.)
Although I have never come across any example or struts documentation which specify the possibility of mentioning java script file also in plug-in tag like : but you can try using it: