velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Boland" <bola...@attbi.com>
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
supported?

bill

-----Original Message-----
From: Geir Magnusson Jr. [mailto:geirm@adeptra.com] 
Sent: Wednesday, July 03, 2002 8:56 AM
To: velocity-user@jakarta.apache.org
Subject: Re: Rules for property lookup and isXxx() support

On 7/3/02 11:37 AM, "Bill Boland" <bolandb@attbi.com> 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
I
> called the method $foo.isNewItem(), it worked just fine returning
"true"
> 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
I
> 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
Map
> lookup into a dynamic property collection and it finds this in the
case
> where $foo.newItem is specified (calling the equiv. of $foo.get(
> "newItem" ) instead of $foo.isNewItem()). I didn't even know this
syntax
> 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 :

 $thing.foo

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 $foo.xxx so
> this must have precedence over the get() lookup for Maps. Luckily, I
am
> in control of the methods for this bean (in this case) but I may not
be
> in the future. The empty string was being returned from the get()
method
> 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
the
> lookup rules for properties or tell me where I'm going wrong? If this
is
> correct, shouldn't (2) and (3) be reversed so that get() is only used
if
> 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
property
> 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
method
> 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:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:
<mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:velocity-user-help@jakarta.apache.org>




--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message