File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes How to handle Date formats when populating the bean using Apache's BeanUtilsBean.populate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to handle Date formats when populating the bean using Apache Watch "How to handle Date formats when populating the bean using Apache New topic
Author

How to handle Date formats when populating the bean using Apache's BeanUtilsBean.populate?

achsu subra
Greenhorn

Joined: Feb 01, 2011
Posts: 11
hi All,

I am using Apache's BeanUtilsBean.populate(Object employee, Map empMap) to automatically populate my bean. All values in empMap are in String format. The populate() automatically takes care of the type conversions from String to int, long, boolean when populating the bean. But does not handle Date formats. Is there any way so that BeanUtils automatically takes care of converting string to Date instead of we manually type casting string to date? Any inputs will be very helpful.

Getting this error because of the Date attribute ... "Exception in thread "main" java.lang.IllegalArgumentException: Cannot invoke Employee.setJoiningDate - argument type mismatch"

Thanks a lot..



regards,
achsu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Check out the following classes:

org.apache.commons.beanutils.ConvertUtils
org.apache.commons.beanutils.Converter

You can use them to register custom converters.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
david lim
Greenhorn

Joined: Apr 22, 2011
Posts: 1
May share how you had resolve this issue please?

Below are my code snipplet and the error it returns:




Apr 22, 2011 11:14:45 PM org.apache.commons.beanutils.converters.DateTimeConverter toDate WARNING: DateConverter does not support default String to 'Date' conversion. Apr 22, 2011 11:14:45 PM org.apache.commons.beanutils.converters.DateTimeConverter toDate WARNING: (N.B. Re-configure Converter or use alternative implementation) Exception in thread "main" org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion. at org.apache.commons.beanutils.converters.DateTimeConverter.toDate(DateTimeConverter.java:468) at org.apache.commons.beanutils.converters.DateTimeConverter.convertToType(DateTimeConverter.java:343) at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156) at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:60) at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:470) at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1008) at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830) at com.ymatch.test.BeanTest.main(BeanTest.java:32)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle Date formats when populating the bean using Apache's BeanUtilsBean.populate?
 
Similar Threads
Trouble setting bean values in jsp via servlet in request scope
doubt in ActionForms
Need Help:How to port HashMap<String-ColmnName, ArayList-ClumnData> to Datatable for multiple colmns
useBean doubt
JPA Composite PK with FK problem