javavalidationstruts1

Struts 1 validator parametrization


I'm working on an application with Struts 1. I have to validate my forms with regex. I found the perfect solution. I add some field validation like that in my validation.xml

<field property="number" 
        depends="required,mask">
        <msg name="mask" key="errors.integer"/>
        <var>
            <var-name>mask</var-name>
            <var-value>^[0-9]*$</var-value>
        </var>
</field>        

But I'm wondering is there any way I can read regex from file and give it to tag?


Solution

  • I found solution.

    I write my java class validator. I declare the validator in validation-rule And then i add to my property name of my validator in 'depend' attribute. I had to write my custom error in application resource properties.

    For more details you can read this article :

    http://blog.kartikshah.com/2007/07/struts-creating-custom-validator.html