You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sgarlata Matt <sg...@bah.com> on 2003/09/27 18:37:21 UTC

Re: [BeanUtils] confused over usage of ConvertUtils [SOLVED]

That's what I was thinking, which made me very displeased because I felt
that ConvertUtils should be able to do this formatting automagically.

Fortunately, ConvertUtils *is* automagical; we just weren't thinking about
Converters correctly :)  To go from String -> Date one uses a DateConverter,
so of course to go from Date -> String one uses a StringConverter.  Isn't
symmetry great?  It's funny neither of us realized this at first.

Matt
----- Original Message ----- 
From: "Henri Yandell" <ba...@generationjava.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Saturday, September 27, 2003 1:19 AM
Subject: Re: [BeanUtils] confused over usage of ConvertUtils


>
> I could be utterly wrong here, but I've always thought the Convert stuff
> was String->Object, even though the API is convert(Class, Object);Object.
> I think the second parameter is effectively a String for uses within
> beanutils.
>
> For Object->String, you would basically want to be looking at a Formatter
> library [java.text.Format, with DateFormat being obvious choices].
>
> Dunno though, could be a lot going on I haven't looked at much in
> BeanUtils. Still trying to understand the whole Locale section.
>
> Hen
>
> On Fri, 26 Sep 2003, Sgarlata Matt wrote:
>
> > I'm sure this is a simple question, but I am quite confused.  I am
trying to
> > do two things using ConvertUtils
> > 1) Convert a String of the form "19 September 2003" to a Date
> > 2) Convert a Date to a String of the form "19 September 2003"
> >
> > #1 (String -> Date) I can do no problem with my own custom Converter
class.
> > Does anyone know how to do #2 (Date -> String) automatically with
> > ConvertUtils?
> >
> > Thanks!
> >
> > Matt
> >
> >
> > ---------------------------------------------------------------------
> > 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
>


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


Re: [BeanUtils] confused over usage of ConvertUtils [SOLVED]

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Henri Yandell wrote:

>On Sat, 27 Sep 2003, Sgarlata Matt wrote:
>
>  
>
>>That's what I was thinking, which made me very displeased because I felt
>>that ConvertUtils should be able to do this formatting automagically.
>>
>>Fortunately, ConvertUtils *is* automagical; we just weren't thinking about
>>Converters correctly :)  To go from String -> Date one uses a DateConverter,
>>so of course to go from Date -> String one uses a StringConverter.  Isn't
>>symmetry great?  It's funny neither of us realized this at first.
>>    
>>
>
>Not really. StringConverter's javadoc says that it takes a String and
>makes it a String. The implementation probably just calls .toString() on
>the Object, which isn't really what would be wanted.
>  
>
But you can register your own converter for the java.lang.String class 
to replace this one.

Craig

>[quick peek shows:
>
>        if (value == null) {
>            return ((String) null);
>        } else {
>            return (value.toString());
>        }
>]
>
>I'd want a getFormatted() method on BeanUtils which uses a FormatUtils to
>handle Object->String in the same way ConvertUtils handles String->Object.
>
>Hen
>
>  
>
>>----- Original Message -----
>>From: "Henri Yandell" <ba...@generationjava.com>
>>To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
>>Sent: Saturday, September 27, 2003 1:19 AM
>>Subject: Re: [BeanUtils] confused over usage of ConvertUtils
>>
>>
>>    
>>
>>>I could be utterly wrong here, but I've always thought the Convert stuff
>>>was String->Object, even though the API is convert(Class, Object);Object.
>>>I think the second parameter is effectively a String for uses within
>>>beanutils.
>>>
>>>For Object->String, you would basically want to be looking at a Formatter
>>>library [java.text.Format, with DateFormat being obvious choices].
>>>
>>>Dunno though, could be a lot going on I haven't looked at much in
>>>BeanUtils. Still trying to understand the whole Locale section.
>>>
>>>Hen
>>>
>>>On Fri, 26 Sep 2003, Sgarlata Matt wrote:
>>>
>>>      
>>>
>>>>I'm sure this is a simple question, but I am quite confused.  I am
>>>>        
>>>>
>>trying to
>>    
>>
>>>>do two things using ConvertUtils
>>>>1) Convert a String of the form "19 September 2003" to a Date
>>>>2) Convert a Date to a String of the form "19 September 2003"
>>>>
>>>>#1 (String -> Date) I can do no problem with my own custom Converter
>>>>        
>>>>
>>class.
>>    
>>
>>>>Does anyone know how to do #2 (Date -> String) automatically with
>>>>ConvertUtils?
>>>>
>>>>Thanks!
>>>>
>>>>Matt
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>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
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>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
>  
>



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


Re: [BeanUtils] confused over usage of ConvertUtils [SOLVED]

Posted by Henri Yandell <ba...@generationjava.com>.

On Sat, 27 Sep 2003, Sgarlata Matt wrote:

> That's what I was thinking, which made me very displeased because I felt
> that ConvertUtils should be able to do this formatting automagically.
>
> Fortunately, ConvertUtils *is* automagical; we just weren't thinking about
> Converters correctly :)  To go from String -> Date one uses a DateConverter,
> so of course to go from Date -> String one uses a StringConverter.  Isn't
> symmetry great?  It's funny neither of us realized this at first.

Not really. StringConverter's javadoc says that it takes a String and
makes it a String. The implementation probably just calls .toString() on
the Object, which isn't really what would be wanted.

[quick peek shows:

        if (value == null) {
            return ((String) null);
        } else {
            return (value.toString());
        }
]

I'd want a getFormatted() method on BeanUtils which uses a FormatUtils to
handle Object->String in the same way ConvertUtils handles String->Object.

Hen

> ----- Original Message -----
> From: "Henri Yandell" <ba...@generationjava.com>
> To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
> Sent: Saturday, September 27, 2003 1:19 AM
> Subject: Re: [BeanUtils] confused over usage of ConvertUtils
>
>
> >
> > I could be utterly wrong here, but I've always thought the Convert stuff
> > was String->Object, even though the API is convert(Class, Object);Object.
> > I think the second parameter is effectively a String for uses within
> > beanutils.
> >
> > For Object->String, you would basically want to be looking at a Formatter
> > library [java.text.Format, with DateFormat being obvious choices].
> >
> > Dunno though, could be a lot going on I haven't looked at much in
> > BeanUtils. Still trying to understand the whole Locale section.
> >
> > Hen
> >
> > On Fri, 26 Sep 2003, Sgarlata Matt wrote:
> >
> > > I'm sure this is a simple question, but I am quite confused.  I am
> trying to
> > > do two things using ConvertUtils
> > > 1) Convert a String of the form "19 September 2003" to a Date
> > > 2) Convert a Date to a String of the form "19 September 2003"
> > >
> > > #1 (String -> Date) I can do no problem with my own custom Converter
> class.
> > > Does anyone know how to do #2 (Date -> String) automatically with
> > > ConvertUtils?
> > >
> > > Thanks!
> > >
> > > Matt
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
>
>
> ---------------------------------------------------------------------
> 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