commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject [validator] Trouble using global constants in variable values
Date Wed, 10 Feb 2010 23:27:32 GMT
Hash: SHA1


Hello, we've been using commons-validator 1.3.1 along with Struts 1.3.8
to do form validation to great success for quite some time (thanks!).

I was recently asked to change our password complexity requirements and
I realized that we had the same "mask" in several different validator
files (we have validator_role1.xml, validator_role2.xml, etc. along with
a global-validator.xml file that contains a custom global validator for
things other than pattern matching).

After a bit of searching, and reading the validator DTD, I saw that one
can define <constant> elements within the <global> element and then use
those constants later in the validators.

Here are the relevant configuration files I have:

- --------------------
        "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.3.0//EN"

      <validator ... />

        <!-- Define constants for the password rules to be used all over -->
          <!-- Requires a letter (\p{L} is "any unicode letter"),
requires a number -->


- ------------------
<?xml version="1.0" ?>
<!DOCTYPE form-validation PUBLIC
        "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.3.0//EN"

    <form name="profileForm">
      <field property="newPassword"
        <arg position="0" key="form.profile.newPassword.prompt"
bundle="User" />
            <arg position="1" name="minlength" key="${var:minlength}"
resource="false" />
            <arg position="2" name="maxlength" key="${var:maxlength}"
resource="false" />
        <msg name="mask" bundle="User" key="error.invalid.password"
/><!-- Specific error message for this one -->



I don't see any errors during startup, and I also don't see any at
runtime (but I did while configuring them in the first place, with typos
and stuff like that showing up in the error logs, so I know that I can
see errors when they /do/ occur). I can see the following messages in my
stdout log during startup:

2010-02-10 18:07:02,899 [main] INFO
org.apache.struts.validator.ValidatorPlugIn- Loading validation rules
file from '/WEB-INF/global-validator.xml'
2010-02-10 18:07:02,899 [main] INFO
org.apache.struts.validator.ValidatorPlugIn- Loading validation rules
file from '/WEB-INF/validate_user.xml'

No errors are displayed afterward, so I assume that everything is copacetic.

Unfortunately for me, when attempting to validate my form using this new
setup, the validation fails and I am presented with the error message
associated with "error.invalid.password", indicating that the "mask"
validation has failed.

I have verified that, if I fail to enter the requisite number of
characters, I'll get a message that says "The field password cannot be
less than 8 characters", which comes from a parameterized message so I
know the "8" is being correctly substituted, here.

Finally, I have checked that my regular expression shown above matches a
variety of inputs that I expect to work (including, say, "Password1",
and "ππππ1ππππ") by writing a simple program that checks against that
expression (the only difference being that each backslash has been
doubled in the source code to that class).

It looks like I have everything right, here, and yet it's not working
for me. Can anyone shed any light on what the problem might be? I'm not
even sure how I can debug this, since I don't know how to dump-out the
regexp that the validator is eventually using.

Any help would be greatly appreciated.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message