commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject Re: BeanUtils Not working !!!
Date Mon, 14 Jul 2008 10:36:57 GMT
Try making your bean classes public?

On Mon, Jul 14, 2008 at 12:57 AM, nise <dhar_nishant@yahoo.com> wrote:
>
> 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){}
>
> }
>
>
>
>
> }
> --
> View this message in context: http://www.nabble.com/BeanUtils-Not-working-%21%21%21-tp18437474p18437474.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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


Mime
View raw message