You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Graham Lounder <gr...@caris.com> on 2004/01/19 20:29:30 UTC
BeanUtils Date Converter
Hey all,
I know this question has been addressed numerous times but I can't seem to
find the answer.
I'm trying to convert strings in my forms to java.sql.Date in my dto. Its
throwing a conversion error when my form value is null or blank. Is there a
way to get nulls or passed through the BeanUtils.copyProperties function? I
read that I may be able to create my own converters too. Is there any
documentation on this?
Cheers,
Graham
Graham Lounder - Java Developer
Spatial Components Division
CARIS www.caris.com
Tel: +1-506-458-8533 Fax: +1-506-459-3849
CARIS has expanded to new office facilities. Our new mailing address is:
115 Waggoners Lane, Fredericton, New Brunswick, E3B 2L4, Canada.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: BeanUtils Date Converter
Posted by Nick Heudecker <ni...@systemmobile.com>.
Graham,
I believe that you need to specify the null returned value:
ConvertUtils.registerConverter(new SqlDateConverter(null), java.sql.Date.class);
On 2004-Jan-19 15:01, Graham Lounder wrote:
> Hey all,
>
> I know this question has been addressed numerous times but I can't seem to
> find the answer.
>
> I'm trying to convert strings in my forms to java.sql.Date in my dto. Its
> throwing a conversion error when my form value is null or blank. Is there a
> way to get nulls or passed through the BeanUtils.copyProperties function? I
> read that I may be able to create my own converters too. Is there any
> documentation on this?
>
> Cheers,
> Graham
>
> Graham Lounder - Java Developer
> Spatial Components Division
> CARIS www.caris.com
> Tel: +1-506-458-8533 Fax: +1-506-459-3849
> CARIS has expanded to new office facilities. Our new mailing address is:
> 115 Waggoners Lane, Fredericton, New Brunswick, E3B 2L4, Canada.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
--
Nick Heudecker
System Mobile, Inc.
Email: nick@systemmobile.com
Web: http://www.systemmobile.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: BeanUtils Date Converter
Posted by Graham Lounder <gr...@caris.com>.
Of course, right after I sent the email, I figured out my problem. I
created the following class, then registered it in my ContextListener using
this line:
ConvertUtils.register(new SqlDateConverter(), java.sql.Date.class);
package com.caris.pmis.util;
import java.sql.Date;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.converters.*;
public class SqlDateConverter implements Converter
{
private org.apache.commons.beanutils.converters.SqlDateConverter
sqlDateConverter = new
org.apache.commons.beanutils.converters.SqlDateConverter();
public Object convert(Class type, Object value)
{
if(value == null || value.toString().length() < 1)
return null;
return sqlDateConverter.convert(type, value);
}
}
Cheers,
Graham
-----Original Message-----
From: Graham Lounder [mailto:graham.lounder@caris.com]
Sent: January 19, 2004 3:30 PM
To: struts-user@jakarta.apache.org
Subject: BeanUtils Date Converter
Hey all,
I know this question has been addressed numerous times but I can't seem to
find the answer.
I'm trying to convert strings in my forms to java.sql.Date in my dto. Its
throwing a conversion error when my form value is null or blank. Is there a
way to get nulls or passed through the BeanUtils.copyProperties function? I
read that I may be able to create my own converters too. Is there any
documentation on this?
Cheers,
Graham
Graham Lounder - Java Developer
Spatial Components Division
CARIS www.caris.com
Tel: +1-506-458-8533 Fax: +1-506-459-3849
CARIS has expanded to new office facilities. Our new mailing address is:
115 Waggoners Lane, Fredericton, New Brunswick, E3B 2L4, Canada.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org