• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with BeanUtils

 
Nisejava Duram
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// 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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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){}
 
Leslie Viviani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic