Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: BeanUtils of apache for populate Object

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default BeanUtils of apache for populate Object

    Hy guys i want insert a LinkedHashMap into MyObject, with custom date format, and i have use BeanUtils with method populate:

    public Object populate(Object obj, LinkedHashMap<String,Object> hash)
    throws IllegalAccessException, InvocationTargetException {
    Date dateempty=null;
    DateTimeConverter dtConverter = new DateConverter(dateempty);
    dtConverter.setPattern("dd/mm/yyyy");
    ConvertUtils.register(dtConverter, java.util.Date.class);
    BeanUtilsBean.getInstance().populate(obj, hash);
    return obj;
    }

    if i call this method with value of hash:
    hash.put("date","10/12/2013"); //this work
    if hash is:
    hash.put("date",""); //now this work
    Last edited by marcobelli; May 28th, 2013 at 10:38 AM. Reason: Solution


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: BeanUtils of apache for populate Object

    Quote Originally Posted by marcobelli View Post
    I have try to set date = null if empty, but not work.
    A LinkedHashMap should have no trouble with a null value.
    If you tried and it is not working, post the code that shows the problem

    What exceptions are you getting? Always post the full text of any error messages with your code and question.

  3. The Following User Says Thank You to jps For This Useful Post:

    marcobelli (May 28th, 2013)

  4. #3
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: BeanUtils of apache for populate Object

    thanks, for help.
    I have update the problem, with a part of stack trace.

  5. #4
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: BeanUtils of apache for populate Object

    I found the solution, if i set DateTimeConverter to null this work:
    Date defaultValue = null;
    DateTimeConverter dtConverter = new DateConverter(defaultValue);
    Thanks!

Similar Threads

  1. Why I populate 2 times the same jTable
    By tomrey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 20th, 2013, 01:28 PM
  2. Why I populate 2 times the same jtable
    By tomrey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 20th, 2013, 01:22 PM
  3. JCombo Box to populate 2 JTextFields
    By jdubicki in forum AWT / Java Swing
    Replies: 2
    Last Post: June 8th, 2012, 11:06 AM
  4. Populate an Object with Other Objects
    By EmSaint in forum Object Oriented Programming
    Replies: 2
    Last Post: October 25th, 2010, 12:45 AM
  5. How to populate a switch statement with a linked list
    By macnasty in forum Collections and Generics
    Replies: 2
    Last Post: May 6th, 2010, 10:47 PM

Tags for this Thread