You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Laurie Harper <la...@holoweb.net> on 2005/06/09 05:18:02 UTC
Converting properties to String
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?
Thanks,
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Converting properties to String
Posted by Laurie Harper <la...@holoweb.net>.
Simon Kitching wrote:
> 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/
Thanks Simon, I'll check that out.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Converting properties to String
Posted by Laurie Harper <la...@holoweb.net>.
Craig McClanahan wrote:
> When originally conceived, ConvertUtils was only concerned with the
> String->Object half.
Yeah, that was the feeling I had... Time for a little software
re-purposing :)
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Converting properties to String
Posted by Craig McClanahan <cr...@gmail.com>.
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 <sk...@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
Re: Converting properties to String
Posted by Simon Kitching <sk...@apache.org>.
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