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
[EMAIL PROTECTED] 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([EMAIL PROTECTED], [EMAIL PROTECTED])
[20060714 17:46:23] DEBUG BeanUtils : setProperty([EMAIL PROTECTED],
firstName, ssss)
[20060714 17:46:23] DEBUG ConvertUtils : Convert string 'ssss' to class
'java.lang.String'
[20060714 17:46:23] DEBUG ConvertUtils : Using converter [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]