commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antony Paul" <antonypau...@hotmail.com>
Subject Re: [BeanUtils] Converting Date to String & String to Date.
Date Fri, 19 Mar 2004 13:57:07 GMT
I did it. I have to register one converter for String. I found one in the
converters package. I write one converter and tested it for performance.
Interestingly my converter is more faster than the one in the package. My
converter contains more lines of code it is posted here.

import org.apache.commons.beanutils.Converter;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringConverter implements Converter{
 public Object convert(Class type,Object obj){
  String value = null;
  if(obj instanceof String)
   return obj;
  if(!(obj instanceof Date)){
   return obj.toString();
  }else{
   try{
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    value = sdf.format((Date)obj);
   }catch(Throwable t){
    t.printStackTrace();
   }
  }
  return value;
 }

};


Thank you for the help

Antony Paul.

----- Original Message -----
From: "Antony Paul" <antonypaul24@hotmail.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Friday, March 19, 2004 6:55 PM
Subject: Re: [BeanUtils] Converting Date to String & String to Date.


> Thank you for reply.
>     I wrote a converter which converts a String to Date(I found an example
> at archives). It converts a String to Date. When data is copied from a
bean
> which have Date type to bean with String property it is not formatting
date.
> Do you understand else I will post code of what I did.
>
> Antony Paul
>
> ----- Original Message -----
> From: "James Carman" <james@carmanconsulting.com>
> To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
> Sent: Friday, March 19, 2004 6:26 PM
> Subject: RE: [BeanUtils] Converting Date to String & String to Date.
>
>
> You could write your own converter, using SimpleDateFormat, if you wish.
I
> would use the source code for some of the other converters as an example.
>
> -----Original Message-----
> From: Antony Paul [mailto:antonypaul24@hotmail.com]
> Sent: Friday, March 19, 2004 7:36 AM
> To: commons-user@jakarta.apache.org
> Subject: [BeanUtils] Converting Date to String & String to Date.
>
> Hi all,
>     I am learning BeanUtils. Converting a String to a destination beans
type
> while copying properties is a nice feature. But is the reverse is
possible.
> It seems that when converting a Date to String it is calling its
toString()
> method. But I dont want this behaviour. I want to format this which is
> required for presentation layer.  Is this possible ?. Does any one have
> written a converter for this.
>
> rgds
> Antony Paul.
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message