struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arulmani V A <arulman...@yahoo.com>
Subject Struts 2 - Global Validation
Date Wed, 03 Feb 2010 20:27:27 GMT
Hi, 

Any idea how to do global validation in Struts 2 ?

For example, in Struts 1, I can define all global regular expression validations in a file
called validation-regexpr.xml such as :


<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
        "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
        "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>
    <global>
        <constant>
            <constant-name>alpha</constant-name>
            <constant-value>[A-Za-z]*</constant-value>
        </constant>
    </global>
</form-validation>

The above global regular expressions can be reused in other validation files as follows : 

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
        "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.2.0//EN"
        "http://jakarta.apache.org/commons/dtds/validator_1_2_0.dtd">

<form-validation>
    <formset>
        <form name="EmployeeForm">
            <field property="EmployeeName" depends="mask">
                <msg name="mask" key="errors.invalid" />
                <arg position="0" key="label.EmployeeName" />
                <var>
                    <var-name>mask</var-name>
                    <var-value>${alpha}</var-value>
                </var>
            </field>
        </form>
    </formset>
</form-validation>


I could not get information on how to do this in Struts 2, no luck with the Struts2 e-books
also. Any help in this regard will be greatly appreciated ....

Regards
Arul




      Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message