The Artima Developer Community
Sponsored Link

Java Answers Forum
copy the properties of one Bean to another Bean

5 replies on 1 page. Most recent reply: Sep 5, 2003 12:49 AM by David

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Mark

Posts: 1
Nickname: mark2003
Registered: Sep, 2003

copy the properties of one Bean to another Bean Posted: Sep 4, 2003 10:10 AM
Reply to this message Reply
Advertisement
How to write a Java helper class that will copy the properties of one Bean to another Bean regardless of class. The helper class should skip properties of the source bean that are not available on the destination bean.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: copy the properties of one Bean to another Bean Posted: Sep 4, 2003 6:55 PM
Reply to this message Reply
I also don't know the exact answer for this. But I think you might have to use reflection facility in Java to do this.

At the same time if you are know Jakarta Struts, they do something very similer when it comes to ActionForm, where they have to automatically setup the form from the request parameters passed. So i think you might get some clue if you download the Struts soruce code and have a look at ActionForm class.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: copy the properties of one Bean to another Bean Posted: Sep 4, 2003 7:40 PM
Reply to this message Reply
Why don't you have a look at XMLEncoder and the XMLDecoder in the API. java.beans.XMLEncoder and java.beans.XMLDecoder. May be if you have a look at the source code of these classes it might open up a door.

zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: copy the properties of one Bean to another Bean Posted: Sep 4, 2003 11:45 PM
Reply to this message Reply
Check the project BeanUtils from Jakarta. It will provide you exactly what you want.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: copy the properties of one Bean to another Bean Posted: Sep 5, 2003 12:00 AM
Reply to this message Reply
Thanx zenykx. I just checked BeanUtils. Your suggestion is more appropreate for the question. Also I think inside Struts too they are using BeanUtils to do the work

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: copy the properties of one Bean to another Bean Posted: Sep 5, 2003 12:49 AM
Reply to this message Reply
My OOD twitch is starting to act up....

The libraries people have been talking about are quite valid places to offer this kind of functionality (well, at least they are arguable).

Why do you want to do this? What about encapsulation etc.?

Flat View: This topic has 5 replies on 1 page
Topic: httpS request  (enter UserInfo and password)  ? Previous Topic   Next Topic Topic: Design patterns web links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use