commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fabian Sergio de Rosa" <fder...@gmail.com>
Subject Re: BeanUtils problem
Date Sat, 15 Jul 2006 00:03:03 GMT
first try using public class Pojo, because if you don't put it the access is
protected o package. then you can try creating first a bean utils

BeanUtils util = new BeanUtils();

2006/7/14, will pugh <willpugh@sourcelabs.com>:
>
> I believe the problem here may be that class Zoo and class Pojo are not
> declared public.
>
> When BeanUtils tries to find an setter that is accessible to it, it
> needs to check for a public method as well as a public class.
>
>     --Will
>
> Tripurari.Sharma@VerizonWireless.com wrote:
>
> >i have two beans:
> >
> >1:
> >class Zoo {
> >
> >       private String firstName = "Zoo1";
> >
> >       public String getFirstName() {
> >               return firstName;
> >       }
> >       public void setFirstName(String firstName) {
> >               this.firstName = firstName;
> >       }
> >}
> >
> >2:
> >
> >class Pojo {
> >
> >       private String firstName = "Pojo1";
> >
> >       public String getFirstName() {
> >               return firstName;
> >       }
> >       public void setFirstName(String firstName) {
> >               this.firstName = firstName;
> >       }
> >}
> >
> >and engine class is:
> >
> >import org.apache.commons.beanutils.BeanUtils;
> >
> >public class ZipcodeLookup {
> >
> >       public static void main(String[] args){
> >
> >               Pojo p = new Pojo();
> >               Zoo z = new Zoo();
> >               try {
> >                       BeanUtils.copyProperties(z, p);
> >                       String ss = new String("ssss");
> >                       BeanUtils.setProperty(z, "firstName", ss);
> >               } catch (Exception e) {
> >                       System.out.println("ex... "+e.toString());
> >               }
> >
> >               System.out.println("Zip: "+z.getFirstName());
> >               System.out.println("Pojo: "+p.getFirstName());
> >
> >       }
> >
> > }
> >
> >when it executes this line:
> >BeanUtils.copyProperties(z, p);
> >it does noting, its not copying the properties to z,
> >
> >and when it executes this line
> >
> >String ss = new String("ssss");
> >BeanUtils.setProperty(z, "firstName", ss);
> >
> >it dies by saying java.lang.reflect.InvocationTargetException: Cannot set
> firstName
> >
> >see log:
> >[20060714 17:46:23] DEBUG BeanUtils : BeanUtils.copyProperties(
> Zoo@116ab4e, Pojo@148aa23)
> >[20060714 17:46:23] DEBUG BeanUtils :   setProperty(Zoo@116ab4e,
> firstName, ssss)
> >[20060714 17:46:23] DEBUG ConvertUtils : Convert string 'ssss' to class '
> java.lang.String'
> >[20060714 17:46:23] DEBUG ConvertUtils :   Using converter
> org.apache.commons.beanutils.converters.StringConverter@bb7465
> >ex... java.lang.reflect.InvocationTargetException: Cannot set firstName
> >Zip: Zoo1
> >Pojo: Pojo1
> >
> >what is the problem, i try injecting data using reflection that works,
> why its not?
> >
> >
> >
> >The information contained in this message and any attachment may be
> >proprietary, confidential, and privileged or subject to the work
> >product doctrine and thus protected from disclosure.  If the reader
> >of this message is not the intended recipient, or an employee or
> >agent responsible for delivering this message to the intended
> >recipient, you are hereby notified that any dissemination,
> >distribution or copying of this communication is strictly prohibited.
> >If you have received this communication in error, please notify me
> >immediately by replying to this message and deleting it and all
> >copies and backups thereof.  Thank you.
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message