commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig McClanahan" <craig...@apache.org>
Subject Re: [Beanutils] Determine type of bean field
Date Thu, 01 Jun 2006 20:43:58 GMT
On 6/1/06, Rahul Akolkar <rahul.akolkar@gmail.com> wrote:
>
> On 6/1/06, Frank W. Zammetti <fzlists@omnytex.com> wrote:
> > On Thu, June 1, 2006 3:32 pm, Craig McClanahan wrote:
> > >> Not sure what's going on... since this is the version of
> > >> setIndexedProperty() without the index, I assume it's going to call
> > >> setChildren(List) and not be looking for the setter with the index,
> > >> correct?  Thanks!
> > >
> > >
> > > Correct.  It's a limitation of BeanUtils that it does not try to use
> the
> > > "indexed" setters if they exist.  It only deals with the actual List
> or
> > > array property as a whole.
> >
> > Excellent, thanks again!  If you'll permit me one last question? :)
> >
> > I have a String[] field "certs" on the bean I'm populating, and I have a
> > List in the object trying to populate it.  I've tried:
> >
> > PropertyUtils.setProperty(obj, "certs", ((List)fieldValues).toArray());
> >
> > ...but that gets me a java.lang.IllegalArgumentException: argument type
> > mismatch.  How does one populate an array?  And specifically, from a
> List?
> >  I guess the setCerts(String[] vals) method doesn't match up with the
> > Object[] that toArray() returns...
> >
> <snip/>
>
> Have you tried:
>
> ((List)fieldValues).toArray(new String[0])
>
> which offers control over the runtime type of the returned array, here
> an array of Strings?


That's part of the equation, but you also have to cast the overall result:

(String[]) ((List)fieldValues).toArray(new String[0])

-Rahul


Craig

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