commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@gmail.com>
Subject Re: Converting properties to String
Date Thu, 09 Jun 2005 05:21:48 GMT
Just for the record, this is why the Converter interface in JavaServer
Faces is explicitly two-way:

    public interface Converter {
        public Object getAsObject(FacesContext context, UIComponent
component, String value);
        public String getAsString(FacesContext context, UIComponent
component, Object value);
    }

When originally conceived, ConvertUtils was only concerned with the
String->Object half.

Craig

On 6/8/05, Simon Kitching <skitching@apache.org> wrote:
> On Wed, 2005-06-08 at 23:18 -0400, Laurie Harper wrote:
> > I understand how to use the Converter interface with BeanUtils to
> > convert String data to a target type. How do I do the reverse? In other
> > words, how to I extend the standard type of X --> String conversions?
> >
> > I realise I can call getConvertUtils().register(myConverter,
> > String.class) but that would replace the default to-String conversions,
> > which is not what I want.
> >
> > I could get the default converter with
> > getConvertUtils.lookup(String.class) and pass that into my converter,
> > allowing me to delegate to it when the source type of the property is
> > not one I'm interested in, but that seems a little cumbersome.
> >
> > Is there an easier / better way?
> 
> ConvertUtils really isn't designed to handle custom mappings to string.
> It is fundamemtally about mapping strings (from xml input, or from web
> forms, etc) to objects. So I don't think there *is* an elegant solution
> to your question within ConvertUtils.
> 
> If you need a general type-conversion framework you might like to look
> at http://morph.sourceforge.net/
> 
> Regards,
> 
> Simon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

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


Mime
View raw message