You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Lai <na...@macau.ctm.net> on 2005/05/10 17:37:14 UTC

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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Pre-processing a text before it is validated

Posted by Gregg D Bolinger <gt...@gmail.com>.
I just thought though you might be wanting to manually remove characters on 
your own for whatever reason, in which case you will need to do something 
before the validator handles it. I don't have an answer for that. Sorry.

Gregg

On 5/10/05, Gregg D Bolinger <gt...@gmail.com> wrote:
> 
> Looks like you need to use a PatternValidator:
> 
> 
> http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/valid/PatternValidator.html
> 
> Gregg
> 
> On 5/10/05, Gregg D Bolinger <gt...@gmail.com> wrote:
> > 
> > Seems like instead of manipulating the field before it is validated you 
> > should be validating against a regular expression. Less work for you. I 
> > can't remember off the top of my head though if there is a regex validator. 
> > I'll take a look.
> > 
> > Gregg
> > 
> > On 5/10/05, Nathan Lai < nathanwh@macau.ctm.net> wrote:
> > > 
> > > 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: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > > 
> > > 
> > 
>

Re: Pre-processing a text before it is validated

Posted by Gregg D Bolinger <gt...@gmail.com>.
Looks like you need to use a PatternValidator:

http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/valid/PatternValidator.html

Gregg

On 5/10/05, Gregg D Bolinger <gt...@gmail.com> wrote:
> 
> Seems like instead of manipulating the field before it is validated you 
> should be validating against a regular expression. Less work for you. I 
> can't remember off the top of my head though if there is a regex validator. 
> I'll take a look.
> 
> Gregg
> 
> On 5/10/05, Nathan Lai <na...@macau.ctm.net> wrote:
> > 
> > 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: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > 
> > 
>

Re: Pre-processing a text before it is validated

Posted by Gregg D Bolinger <gt...@gmail.com>.
Seems like instead of manipulating the field before it is validated you 
should be validating against a regular expression. Less work for you. I 
can't remember off the top of my head though if there is a regex validator. 
I'll take a look.

Gregg

On 5/10/05, Nathan Lai <na...@macau.ctm.net> wrote:
> 
> 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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

Re: Pre-processing a text before it is validated

Posted by Bryan Lewis <br...@maine.rr.com>.
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" <na...@macau.ctm.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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