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 Problem with BeanUtils Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 41591
    
  55
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