commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "usha rani" <usha_k...@hotmail.com>
Subject Re: copyproperties
Date Mon, 20 Jan 2003 07:11:33 GMT
Hi

i am getting the following error

my classes are

public class OrigBean {
    ...
    public String getApplydate();
    public void setApplydate(String applydate);
    ...
  }

  public class DestBean {
    ...
    public int getApplydate();
    public void setApplydate(java.sql.Date applydate);
    ...
  }

when i use the
OrigBean orig = new OrigBean();
OrigBean.setApplydate("20-JAN-2003");
DestBean dest = new DestBean();
BeanUtils.copyProperties(OrigBean ,DestBean );

org.apache.commons.beanutils.ConversionException: For input string: "JAN"
        at 
org.apache.commons.beanutils.converters.SqlDateConverter.convert(SqlDateConverter.java:162)
        at 
org.apache.commons.beanutils.ConvertUtils.convert(ConvertUtils.java:373)
        at 
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:903)
        at 
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
        at 
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978)
        at 
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:779)
        at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:246)
        at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
        at 
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
        at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
        at 
org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
        at 
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
        at 
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
        at 
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
        at java.lang.Thread.run(Thread.java:536)
Caused by: java.lang.NumberFormatException: For input string: "JAN"
        at 
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:426)
        at java.lang.Integer.parseInt(Integer.java:476)
        at java.sql.Date.valueOf(Date.java:97)
        at 
org.apache.commons.beanutils.converters.SqlDateConverter.convert(SqlDateConverter.java:157)


For example:

  public class OrigBean {
    ...
    public String getCount();
    public void setCount(String count);
    ...
  }

  public class DestBean {
    ...
    public int getCount();
    public void setCount(int count);
    ...
  }

and in your application:

  OrigBean orig = new OrigBean();
  orig.setCount("123");
  DestBean dest = new DestBean();
  BeanUtils.copyProperties(dest, orig);
  ... dest.getCount() will return 123 here ...




>From: "Craig R. McClanahan" <craigmcc@apache.org>
>Reply-To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
>To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
>Subject: Re: copyperoperties
>Date: Sun, 19 Jan 2003 22:01:54 -0800 (PST)
>
>
>
>On Mon, 20 Jan 2003, usha rani wrote:
>
> > Date: Mon, 20 Jan 2003 13:19:07 +0800
> > From: usha rani <usha_kaza@hotmail.com>
> > Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> > To: commons-user@jakarta.apache.org
> > Subject: copyperoperties
> >
> > Hi
> >
> > can i use BeanUtils.copyProperties() to copy from one bean to another. 
>where
> > the origin bean is having String datatype and destination bean is having
> > Integer datatype
> >
>
>Um, just use it?  :-)
>
>The important rule for copyProperties() is that the property names in the
>two beans must be the same.  Then, as the copying takes place, BeanUtils
>will notice the two data types are not the same, and look up a Converter
>that knows how to perform the needed conversion.
>
>For example:
>
>   public class OrigBean {
>     ...
>     public String getCount();
>     public void setCount(String count);
>     ...
>   }
>
>   public class DestBean {
>     ...
>     public int getCount();
>     public void setCount(int count);
>     ...
>   }
>
>and in your application:
>
>   OrigBean orig = new OrigBean();
>   orig.setCount("123");
>   DestBean dest = new DestBean();
>   BeanUtils.copyProperties(dest, orig);
>   ... dest.getCount() will return 123 here ...
>
>If you want to use a data type that does not have a preregistered
>converter, you'll have to create and register your own.  For more info,
>see the JavaDocs for commons-beanutils, available online at:
>
>   http://jakarta.apache.org/commons/beanutils/api/
>
>In particular, read the "Package Description" section for the
>org.apache.commons.beanutils package.
>
>
> > Thanks
> > usha
> >
>
>Craig
>
>
>--
>To unsubscribe, e-mail:   
><mailto:commons-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: 
><mailto:commons-user-help@jakarta.apache.org>

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus


Mime
View raw message