velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Boland" <>
Subject RE: Rules for property lookup and isXxx() support
Date Wed, 03 Jul 2002 17:15:28 GMT
Thanks Geir,

I will post a documentation defect. Is there a reason isFoo() is tried
AFTER get when it is the JavaBeans standard and seems equiv. to getFoo()
(IMHO)? Or is this for some backward compatibility when isFoo() was not


-----Original Message-----
From: Geir Magnusson Jr. [] 
Sent: Wednesday, July 03, 2002 8:56 AM
Subject: Re: Rules for property lookup and isXxx() support

On 7/3/02 11:37 AM, "Bill Boland" <> wrote:

> Veloci-gurus,
> I noticed a problem with a template I created that used a boolean
> property (named newItem) of bean (foo) in the context. I placed
> $foo.newItem into a template and it returned an empty String value. If
> called the method $foo.isNewItem(), it worked just fine returning
> or "false". I noticed in some archived messages that the introspection
> of isXxx() was not supported as well as full support for the JavaBean
> specification but this was a while ago. Is it still unsupported or am
> missing something?

The isXXX should be there now.  I notice below that you are using
1.3-rc1 -
it should work in there.

I'll take a look.

> My assumption (I know...shame on me) was that it followed the
> specification since the documentation doesn't explicitly say that
> properties are derived from only "getXxxx()" methods.

Yes - we departed from the beanspec.
> [Doing some researching/reading while writing this...]
> I think that in my case, $foo also has a "get()" method to support a
> lookup into a dynamic property collection and it finds this in the
> where $foo.newItem is specified (calling the equiv. of $foo.get(
> "newItem" ) instead of $foo.isNewItem()). I didn't even know this
> feature existed for Maps! It's right there in the documentation but I
> easily overlooked it. Maybe that is why it returns an empty string?

Yes, our approach is :


1) try getFoo()
2) try getfoo() [for wacky people...]
3) try get("foo")
4) try isFoo()

> So the precedence of the rules for properties in Velocity are just
> different but not explicitly documented. I was able to get Boolean
> values using isXxx() methods from other objects that did not have a
> get() method (example: $req.isSecure() in HttpServletRequest object),
> but not my bean. Once I add a getXxxx() method to my bean (along with
> the isXxx() method), I am able to get the property using $ so
> this must have precedence over the get() lookup for Maps. Luckily, I
> in control of the methods for this bean (in this case) but I may not
> in the future. The empty string was being returned from the get()
> when the "newItem" key was not found in the internal Map.
> Below is what I think the internal rules are for mapping the property
> name to a method on the bean. Could someone confirm this or document
> lookup rules for properties or tell me where I'm going wrong? If this
> correct, shouldn't (2) and (3) be reversed so that get() is only used
> getXxx() AND isXxx() are not specified?
> (1) See if the bean has a getXxx() method where Xxx is the property
> name. If so, use that method to get the value.
> (2) See if the bean has a get( Object ) method. If so, use the
> name as a key to this method and return the value.
> (3) See if the bean has an isXxx() method where Xxx is the property
> name. If so use that method to get the value.

Yep - with the getxxxx() as well as 1a)

> I know I can explicitly get around these rules by specifying the
> and not the property but I felt that (1) if I've come across this,
> someone else is bound to at some time or another and (2) it should be
> documented since it doesn't follow the JavaBean spec.

Agreed.  Post a patch for the user guide :)
> Using 1.3-rc1 of Velocity.
> Thanks for any help.
> bill
> --
> To unsubscribe, e-mail:
> <>
> For additional commands, e-mail:
> <>

Geir Magnusson Jr. 
Research & Development, Adeptra Inc.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message