struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antony Joseph" <ajosep...@lycos.com>
Subject Re: Is there a way to auto-trim String properties in DynaForms?
Date Tue, 01 Mar 2005 18:29:34 GMT
Struts uses ConverterUtils to populate action forms.

1)Register the string converter which trims leading and trailing spaces with ConvertUtils.
You want to do this during application initialization in a ServletContextListener or a Struts
plugin


        TrimStringConverter trimString = new TrimStringConverter();
        ConvertUtils.register(trimString, String.class);



2) The class which strips the leading and trailing spaces.

public class TrimStringConverter implements Converter {
    /**
     * Trims leading and trailing white spaces.
     * @param type   the type of the class
     * @param value  the value
     * @return       the trimmed string
     */
    public Object convert(Class type, Object value) {
        if (value == null)
            return null;
        else
            return value.toString().trim();
    }
}


----- Original Message -----
From: "K.C. Baltz" <kc.baltz@firefox.co.uk>
To: "Struts Users Mailing List" <user@struts.apache.org>
Subject: Is there a way to auto-trim String properties in DynaForms?
Date: Tue, 01 Mar 2005 09:53:20 -0800

> 
> I'm reposting this in the hopes that there is an answer out there.
> 
> > It would be really nice if I could programmatically indicate that 
> > certain fields in a DynaForm should be automatically trimmed of 
> > whitespace.  Is there a way to do this?
> > Alternatively, is there a way to get the behavior of the 
> > "required" validation when using validwhen?  "required" doesn't 
> > accept values that are nothing but whitespace whereas there's no 
> > way to test for this when using validwhen.
> 
> K.C. Baltz
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org



Antony Joseph
Available for consulting
http://www.logicden.com

-- 
_______________________________________________
Find what you are looking for with the Lycos Yellow Pages
http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10


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


Mime
View raw message