commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marko Umek <umek.ma...@gmail.com>
Subject Re: BeanUtils Not working !!!
Date Mon, 14 Jul 2008 10:16:18 GMT
Try to exchange b1 and a1:

BeanUtils.copyProperties(a1,b1);

May be there is a documentation bug ;-)



nise schrieb:
> 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
>
> when i run the code .. it just prints out
>
> john
> null
>
> instead of
>
> john
> john
>
> which i was expecting
>
>
> wht cd i be doing wrong
>
> thanks
>
> nise
>
>
> 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){}
>
> }
>
>
>
>
> } 
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message