On 3 Apr 2002, David M. Karr wrote:

> Date: 03 Apr 2002 16:49:12 -0800
> From: David M. Karr <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: strust.taglib.bean proposal
>
> >>>>> "Nicolas" == Nicolas De Loof <[EMAIL PROTECTED]> writes:
>
>     Nicolas>        String setterName = "set"
>     Nicolas>           + arg.substring(0,1).toUpperCase()
>     Nicolas>           + arg.substring(1);
>     Nicolas>        try {
>     Nicolas>           System.out.println("setterName "+setterName);
>     Nicolas>           Method setter = parentTag.getClass().getMethod(
>     Nicolas>              setterName, new Class[] { String.class } );
>
>     Nicolas>           setter.invoke(parentTag,
>     Nicolas>              new Object[] {getBodyContent().getString()} );
>
> I believe the functionality in this block is basically what
> "BeanUtils.populate()" does, although with a little more overhead.
>

BeanUtils and PropertyUtils actually do somewhat more than this:

* Property setter names do *not* have to start with "set" -- bean
  developers can supply an additional BeanInfo class to define the
  get and set method names.  BeanUtils uses the standard introspection
  capabilities to do this lookup.

* There are some special case rules for property names that start with
  multiple capital letters that the introspection code deals with.

* Because the introspection is the expensive part, the results are cached.
  Therefore, BeanUtils will execute repeated property sets on the same
  bean class much faster than the above code, which does a
  getMethod() lookup every single time.

* The BeanUtils version of the property setters (including the ones
  called in populate()) do automatic type conversion for you, while
  the PropertyUtils version of the property setters assumes you already
  have the right data type.

* The library methods know how to deal with indexed and mapped setters
  as well as scalar properties.

So, the above code (if included in the tag) would most likely be replaced
by a call to PropertyUtils.getProperty() to take advantage of what the
library can do.

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to