Important ***Struts Validation Issue *** Important


Web tier: servlets, JSP, Web frameworks: Important ***Struts Validation Issue *** Important

  1. Hi,
    I'm working on a protal which is making use of Struts framework. For the data validation, Struts Validator framework is being used in the same. But the thing is that even after making sure everything is rite, the validations are not happening - on both sides, client side as well as server side.
    Here are the prototype code snippets for your reference:
    1) FORM class
    public class StrutsValidationForm extends ValidatorForm

    2) struts-config.xml
    (i)<form-bean name="myForm" type="com.gxs.tiger.struts.form.StrutsValidationForm"/>
    <action path="/ValidationTest"
    validate="true" >
    <forward name="success" path="/success.jsp"/>
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathname" value="/WEB-INF/validator-rules.xml"/>
    <set-property property="pathname" value="/WEB-INF/validation.xml"/>

    3) Validation.xml
    <form name="myForm">
    <field property="name" depends="required,mask">
    <arg0 key="" resource="true"/>

    # Resource Bundle for the validation exercise
    test.fname = Name
    test.age = Age
    test.dob = Date Of Birth
    test.emailID = Email
    errors.required={0} is required.{0} is an invalid e-mail address.{0} is not a date.
    errors.maxlength={0} can not be greater than {1} characters.
    errors.integer={0} must be an integer.
    errors.range={0} is not in the range {1} through {2}.
    errors.invalid={0} is invalid.

    5) Tages used in the input jsp
    <html:javascript formName="myForm"/>

    Could anyone tell me what's wrong with this code or am I missing out any step in turning the validaion ON ? Because the input page is generated without the javascript code. It'll be a great help, if anyone can throw a light on what exactly is wrong with this example ?????
  2. Struts Validation Issue[ Go to top ]

    Do you have something like this in in the input jsp?
    <form action="xzyAction" onsubmit="validateMyForm(this);">

    Does your form extends ValidatorForm? (I think it is called ValidatorForm, but it could be different)
  3. Thanks Alex for your reply. But as you pointed out, I'm using the onsubkit feature in the <html:form> tag. But even after that the mappings are not taking place for the JavaScript. Any idea if any configuration issue involved here ??