You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2005/11/01 04:50:36 UTC

[Jakarta-commons Wiki] Update of "ValidatorVersion120" by NiallPemberton

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by NiallPemberton:
http://wiki.apache.org/jakarta-commons/ValidatorVersion120

The comment on the change is:
Add page describing Validator 1.2.0

New page:
= Validator Version 1.2.0 =
The aim of this page is to provide a summary of the changes in '''Validator 1.2.0'''. For a full list of the changes in Validator 1.2.0 see the [http://people.apache.org/~niallp/commons-validator/1.2.0-rc2/site/changes-report.html Changes Report].

----

== 1. Validator Inheritance ==
Probably the most significant change in Validator 1.2.0 is the introduction of ''inheritance'' which comes in two forms:
 * '''Explicit''' Form inheritance
 * '''Implicit''' ''Locale'' inheritance

=== 1.1 Explicit Form Inheritance ===
Explicit Form Inheritance is where one [http://people.apache.org/~niallp/commons-validator/1.2.0-rc2/site/apidocs/org/apache/commons/validator/Form.html Form] can inherit from another by specifying the name of the form to inherit using the new '''extends''' property (which is also an new attribute in the [http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/validator/trunk/conf/share/validator_1_2_0.dtd?view=markup validator_1_2_0.dtd]). See [http://issues.apache.org/bugzilla/show_bug.cgi?id=27870 #27870].


In the following example '''nameForm''' inherits from '''baseForm''', overriding the '''lastName''' field...
{{{
    <formset>
        <form name="baseForm">
            <field property="firstName" depends="required">
                ...
            </field>
            <field property="lastName" depends="required">
                ...
            </field>
        </form>

        <form name="nameForm" extends="baseForm">
            <field property="lastName" depends="required,minLength">
                ...
            </field>
        </form>
    </formset>
}}}

=== 1.2 Implicit Locale Inheritance ===
Prior to Validator 1.2.0, forms defined in different '''!FormSet''''s (i.e. different ''Locales'') were treated completely separtely. Now Forms with the same name ''implicitly'' inherit from those in ''less specific'' locales.

For example, if you have a form named !CustomerForm defined in a !FormSet for the '''French''' language (no country) and also in a !FormSet for the '''Candian French''' locale then the ''Candian French'' version of the Form will inherit from the ''French'' one.

See [http://issues.apache.org/bugzilla/show_bug.cgi?id=30955 Bug 30955], [http://issues.apache.org/bugzilla/show_bug.cgi?id=16920 Bug 16920] and [http://issues.apache.org/bugzilla/show_bug.cgi?id=37310 Bug 16920].

'''N.B.''' See Section '''2. Variables in Resource Bundles''' which may remove your need to have multiple !FormSet's for different locales altogether.

== 2. Variables in Resource Bundles ==
One motivation for having different Form Sets was due to the fact that '''variable''' values needed to be different for different locales. Validator 1.2.0 has the facility to specify variable values in resource bundles which removes the need for multiple formsets in this instance

Two new properties have been added to [http://people.apache.org/~niallp/commons-validator/1.2.0-rc2/site/apidocs/org/apache/commons/validator/Var.html Variable] - '''resource''' and '''bundle'''. Setting '''resource''' to '''true''' (default is ''false'') indicates that the variable's value is a ''resource key''. Additionally the (optional) '''bundle''' property can be set to the name of an alternative resource bundle.

In the following example the value of '''datePattern''' variable is specified in the '''validatorVariables''' bundle under a key of '''dateOfBirth.pattern'''.

{{{
    <formset>
        <form name="EmployeeForm">
            <field property="dateOfBirth" depends="date">

                <var resource="true" bundle="validatorVariables">
                    <var-name>datePattern</var-name>
                    <var-value>dateOfBirth.pattern</var-value>
                </var>

            </field>
        </form>
    </formset>
}}}

'''N.B.''' Validator provides the facility to indicate that a variable's value is in a resource bundle - but it is down to individual configured validators to actually take notice of these properties and retrieve the value from the resource bundle. Struts 1.3 has been upgraded to take advantage this feature and is an example of what custom validators need to do. See the Struts [http://svn.apache.org/viewcvs.cgi/struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java?view=markup FieldChecks] class.

== 3. Arg0-Arg3 Deprecations Removed ==
A number of deprecations have been removed in Validator 1.2.0 - however probably the biggest impact will be the '''Arg0-Arg3''' elements (which were replaced by '''Arg''').

So for example, in the validator config...
{{{
        <arg0 key="first.key">
        <arg1 key="second.key">
}}}
should be changed to
{{{
        <arg key="first.key"  position="0">
        <arg key="second.key" position="1">
}}}
Position is however ''optional'' and if omitted, validator will automatically allocate a ''position'' value - see [http://issues.apache.org/bugzilla/show_bug.cgi?id=31194 Bug 31194] for details.

Additionally, this issue only arises if you upgrade to the new version of the Validator DTD - previous versions of the DTD using arg0-arg3 will continue to work in Validator 1.2.0.

== 4. Changes to Validators ==

A few new validators have been added:

 * A new '''ISBN Validator''' for validating book numbers has been added (see [http://issues.apache.org/bugzilla/show_bug.cgi?id=31489 #31489]).
 * New ''locale aware'' '''byte''', '''short''', '''integer''', '''long''', '''float''' and '''double''' validations added (see [http://issues.apache.org/bugzilla/show_bug.cgi?id=21282 #21282]).
 * New '''Minimum/Maximum''' value validators added (see [http://issues.apache.org/bugzilla/show_bug.cgi?id=29015 #29015]).

The following validator's issues have been fixed:

 * '''Email''' Validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=23990 Bug 23990], [http://issues.apache.org/bugzilla/show_bug.cgi?id=29541 Bug 29541], [http://issues.apache.org/bugzilla/show_bug.cgi?id=33409 Bug 33409], [http://issues.apache.org/bugzilla/show_bug.cgi?id=31644 Bug 31644]
 * '''URL''' Validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=30686 Bug 30686]
 * '''Float''' Validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=32351 Bug 32351] and [http://issues.apache.org/bugzilla/show_bug.cgi?id=36878 Bug 36878]
 * '''Double''' Validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=36878 Bug 36878]
 * '''Credit Card''' Validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=35926 Bug 35926]
 * '''Date''' Validator no longer logs the ParseException for an invalid date.

The following '''JavaScript''' validator's issues have been fixed:

 * The Strategy for locating a form using name/id has changed to correct various issues - see [http://issues.apache.org/bugzilla/show_bug.cgi?id=35127 Bug 35127], [http://issues.apache.org/bugzilla/show_bug.cgi?id=35294 Bug 35294] and [http://issues.apache.org/bugzilla/show_bug.cgi?id=31534 Bug 31534]
 * '''Required''' validator fixed for [http://issues.apache.org/bugzilla/show_bug.cgi?id=15912 Bug 15912] and [http://issues.apache.org/bugzilla/show_bug.cgi?id=33047 Bug 33047]
 * '''Date''' validator enhanced to support ''datePattern'' - see [http://issues.apache.org/bugzilla/show_bug.cgi?id=22384 Bug 22384]

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org