The standard way is to write your own validator that does your processing
before calling the standard validator's method.  Here's a simple one I wrote
recently to allow dollar signs and commas in the user's input.

/**
 *  Provides input validation for strings treated as numbers.  Derived from
 *  NumberValidator.  Trims the input string and ignores dollar signs and
 *  commas.
 */
public class DollarValidator extends
org.apache.tapestry.valid.NumberValidator
{
    public Object toObject(IFormComponent field, String value) throws
ValidatorException
    {
        if (value != null) {
            // trim() returns a copy of the string as desired.
            value = value.trim();

            // Strip out the dollar signs and commas.
            List pieces = CString.componentsSeparatedByDelimiters(value,
"$,");
            value = CString.componentsJoinedByString(pieces, "");
        }

        return super.toObject(field, value);
    }
}


----- Original Message ----- 
From: "Nathan Lai" <[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>
Sent: Tuesday, May 10, 2005 11:37 AM
Subject: Pre-processing a text before it is validated


> In Tapestry, how can I pre-process the value of a valid field before it
> is validated? For instance, I want to filter out all non-alplanumeric
> symbols in a string that is supposed to contain only alphanumeric
> characters.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to