This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Problem with BeanUtils Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Problem with BeanUtils" Watch "Problem with BeanUtils" New topic
Author

Problem with BeanUtils

Nisejava Duram
Greenhorn

Joined: Jul 04, 2008
Posts: 7
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.LogFactory;

Hi,
I am using BeanUtils for copying the contents of one bean into another using reflection.
The code is really simple and it compiles and runs fine but does not give the desired output.
It basically *DOES NOT* copy the property 'name' from the source to the destination bean

wht cd i be doing wrong

thanks

nise



class A{

int name;

public int getName()
{

return name;

}

public void setName(int name)
{
this.name= name;
}


}

class B
{

int name;

public int getName()
{

return name;

}

public void setName(int name)
{
this.name= name;
}


}




public class test {

public static void main(String args[])
{

A a1= new A();
B b1= new B();

a1.setName(1);
System.out.println(a1.getName());
try{
BeanUtils.copyProperties(b1,a1);
System.out.println(b1.getName());
}
catch(Exception e){}

}




}
Nisejava Duram
Greenhorn

Joined: Jul 04, 2008
Posts: 7
// SORRY I AM POSTING THE CODE AGAIN. This is the code that is not working


import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.LogFactory;

class A{

String name;

public String getName()
{

return name;

}

public void setName(String name)
{
this.name= name;
}


}

class B
{

String name;

public String getName()
{

return name;

}

public void setName(String name)
{
this.name= name;
}


}




public class test {

public static void main(String args[])
{

A a1= new A();
B b1= new B();

a1.setName("John");
System.out.println(a1.getName());
try{
BeanUtils.copyProperties(b1,a1);
System.out.println(b1.getName());
}
catch(Exception e){}

}




}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
I'm not much familiar with BeanUtils, but this is a bad idea, especially if you're trying to track down a problem:
catch(Exception e){}


Ping & DNS - my free Android networking tools app
Leslie Viviani
Greenhorn

Joined: Jun 18, 2008
Posts: 4
Make sure your class A and class B are declared public.

See the following for more information:
http://commons.apache.org/beanutils/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/package-summary.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with BeanUtils
 
Similar Threads
How to handle Date formats when populating the bean using Apache's BeanUtilsBean.populate?
Extracting hierarchy of objects from Vector
How can I get a run() method to return a string variable, when run() method is required to be void ?
is this correct way of implimenting comparable interface
Why Object.clone() ?