• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

copy from one bean to other bean

Hi,

I am going through below link on how to copy from one bean to other bean
http://www.avajava.com/tutorials/lessons/how-do-i-copy-properties-from-one-bean-to-another.html?page=1


I have nto clearly understood how author is copy pasting.

I also did not see usage of ToStringBuilder method.

What is the practical use of ToStringBuilder method.

I also wonder why there is dependency bewteen
BeanUtils on the Commons lang and commons util jars

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
  • 4
  • 3
1 Solution
 
girionisCommented:
These classes are part of the Apache Jakarta Commons, in order to find out how they copy data from one bean to another you better look at the source code. I guess they use reflection to find the properties of one bean, and use the mutator methods of the second bean to set the values.
0
 
gudii9Author Commented:
reflection to find the properties of one bean

How to use the reflection and mutation to find the properties of beans. please advise
0
 
girionisCommented:
I think the best place to start is the java tutorial on reflection.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gudii9Author Commented:
I am referring the link(http://docs.oracle.com/javase/tutorial/reflect/class/index.html)

They said as below which is not clear to me.
Every object is either a reference or primitive type
all of the wrapper classes for primitive types such as java.lang.Double, the interface java.io.Serializable, and the enum javax.swing.SortOrder.


How object can be primitive type?
also how serializable and SortOrder are primitive types.
please advise
0
 
girionisCommented:
It says the wrappers for the primitive types, not the primitive types. Read it again, it does not say the primitive types are objects.
0
 
gudii9Author Commented:
sounds good.

Every object is either a reference or primitive type


But above statement does not say wrapper. I wonder why. please advise
0
 
gudii9Author Commented:
I have not understood the gist of this example. what exactly author is trying to do.

     public FromBean(String name, String aProp, String bProp) {
            this.name = name;
            this.aProp = aProp;
            this.bProp = bProp;
      }

      public String getAProp() {
            return aProp;
      }

      public void setAProp(String prop) {
            aProp = prop;
      }


why there is no this for  setter methods (aProp = prop;)similar to constructor (this.name = name;)

why FromBean and ToBean has common properties like name, bProp

Is no argument constructor is mandotory for a bean even when there is argument constructor.
please advise
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now