Re: [BeanUtils] Converting Date to String String to Date.

2004-03-19 Thread Antony Paul
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 [EMAIL PROTECTED]
To: 'Jakarta Commons Users List' [EMAIL PROTECTED]
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:[EMAIL PROTECTED]
Sent: Friday, March 19, 2004 7:36 AM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [BeanUtils] Converting Date to String String to Date.

2004-03-19 Thread Antony Paul
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-);
value = sdf.format((Date)obj);
   }catch(Throwable t){
t.printStackTrace();
   }
  }
  return value;
 }

};


Thank you for the help

Antony Paul.

- Original Message -
From: Antony Paul [EMAIL PROTECTED]
To: Jakarta Commons Users List [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
 To: 'Jakarta Commons Users List' [EMAIL PROTECTED]
 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:[EMAIL PROTECTED]
 Sent: Friday, March 19, 2004 7:36 AM
 To: [EMAIL PROTECTED]
 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [BeanUtils] Converting Date to String String to Date.

2004-03-19 Thread James Carman
You might want to call it StringToDateConverter and I'd provide the date
format string as a parameter to the constructor.

-Original Message-
From: Antony Paul [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 19, 2004 8:57 AM
To: Jakarta Commons Users List
Subject: Re: [BeanUtils] Converting Date to String  String to Date.

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-);
value = sdf.format((Date)obj);
   }catch(Throwable t){
t.printStackTrace();
   }
  }
  return value;
 }

};


Thank you for the help

Antony Paul.

- Original Message -
From: Antony Paul [EMAIL PROTECTED]
To: Jakarta Commons Users List [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
 To: 'Jakarta Commons Users List' [EMAIL PROTECTED]
 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:[EMAIL PROTECTED]
 Sent: Friday, March 19, 2004 7:36 AM
 To: [EMAIL PROTECTED]
 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]