commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: [BeanUtils] Handling array creation?
Date Thu, 08 Sep 2005 19:12:00 GMT
I just can't get any love with this :)

I'm trying to configure a bean manually (forget the whole configuring from
an XML file for just a minute), and I'm baseing the code on what Niall
posted this morning... here's what I have:

public class DFTestBean {
  private String[] certifications;
  public void setCertifications(int inIndex, String inValue) {
    certifications[inIndex] = inValue;
  }
  public String getCertifications(int inIndex) {
    return certifications[inIndex];
  }
  public void setCertifications(String[] inArray) {
    certifications = inArray;
  }
  public String[] getCertifications() {
    return certifications;
  }
}

Then, in another class I'm doing this:

DFTestBean obj = new DFTestBean();
try {
  Object certArray = Array.newInstance(String.class, 3);
  Converter converter = ConvertUtils.lookup(String.class);
  Object v;
  v = converter.convert(String.class, "CNE");
  Array.set(certArray, 0, v);
  v = converter.convert(String.class, "SCJD");
  Array.set(certArray, 1, v);
  v = converter.convert(String.class, "INETP");
  Array.set(certArray, 2, v);
  BeanUtils.setProperty(obj, "certifications", certArray);
} catch (IllegalAccessException iae) {
  iae.printStackTrace();
} catch (InvocationTargetException ite) {
  ite.printStackTrace();
}

When this executes, I get the following exception:

[ERROR] PropertyUtils - Method invocation failed.
<java.lang.IllegalArgumentExce
ption: argument type mismatch>java.lang.IllegalArgumentException: argument
type
mismatch
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyU
tilsBean.java:1773)
        at
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(Prop
ertyUtilsBean.java:1759)
        at
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(Prop
ertyUtilsBean.java:1648)
        at
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUt
ilsBean.java:1677)
        at
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.
java:1022)
        at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:313
)

I even tried it without the converter in the mix, as I didn't figure it
was needed in this instance, but no harm I figured (and I wanted to use
Niall's code as close to unchanged as I could).  No difference.

It seems to be telling me there is no method in the bean with a matching
signature, and I suppose if the underlying type of the array being passed
in isn't recognized as String then that might make sense, but I'm reaching
here, it seems like it should be working (Niall's code was pretty
straight-forward after all, and the only different here that I can see is
it's not in a look and I'm not dynamically getting the property's type,
neither of which I can see mattering).

I also tried dynamically getting the property type as Niall showed, but
then I get simply:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtil
s.java:334)
        at
org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtil
s.java:286)
        at
org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtil
s.java:248)

Any ideas?  Thanks!



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


Mime
View raw message