You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bobby rullo <br...@alexanderinteractive.com> on 2005/02/25 18:15:53 UTC
OGNL: Test for existence?
Is there a way to test for the existence of a property or object within a
collection in OGNL? The docs say you can coerce a null into a boolean false so I
tried:
<span jwcid="@Conditional" condition="ognl:page.beans.delegate" >
...
</span>
But that doesn't work (ognl.NoSuchPropertyException). I also tried to be clever
with:
<span jwcid="@Conditional" condition="ognl:page.beans['delegate']" >
...
</span>
but that yielded the same results.
Thanks
Bobby
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: OGNL: Test for existence?
Posted by bobby rullo <br...@alexanderinteractive.com>.
matthew c. mead <m-apache <at> goof.com> writes:
>
> Try it - I think it would. getClass() would be executed within the
> context of the tapestry "enhanced" class. When you declare the
> property-specification in the page specification Tapestry creates an
> accessor/mutator for it. In fact, since I work with my properties a lot
> in code, I often make the page class abstract and add abstract
> accessors/mutators so I can deal with the tapestry properties.
How interesting - are you saying that Tapestry will make a new Bean Provider
class for every page specification with a getXXXXX method for each bean? That's
cool.
In the meantime I discovered the canProvideBean(String beanname) on the
IBeanProvider interface which works just fine!
Thanks Matthew,
Bobby
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: OGNL: Test for existence?
Posted by "matthew c. mead" <m-...@goof.com>.
Try it - I think it would. getClass() would be executed within the
context of the tapestry "enhanced" class. When you declare the
property-specification in the page specification Tapestry creates an
accessor/mutator for it. In fact, since I work with my properties a lot
in code, I often make the page class abstract and add abstract
accessors/mutators so I can deal with the tapestry properties.
-matt
bobby rullo wrote:
>>boolean hasPropertyAccessor(String propertyName) throws SecurityException {
>> try {
>> return getClass().getMethod("get" + propertyName.substring(0,
>>1).toUpperCase() + propertyName.substring(1, propertyName.length()), new
>>Class[] {}) != null;
>> } catch (NoSuchMethodException e) {
>> return false;
>> }
>>}
>>
>>
>
>
>That would work for proper java beans...but I am really looking to test the
>existence of a tapesrty bean that is defined in the Page specification. I don't
>think that your solution would work in this case....
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
--
matthew c. mead
http://www.goof.com/
Re: OGNL: Test for existence?
Posted by bobby rullo <br...@alexanderinteractive.com>.
>
> boolean hasPropertyAccessor(String propertyName) throws SecurityException {
> try {
> return getClass().getMethod("get" + propertyName.substring(0,
> 1).toUpperCase() + propertyName.substring(1, propertyName.length()), new
> Class[] {}) != null;
> } catch (NoSuchMethodException e) {
> return false;
> }
> }
That would work for proper java beans...but I am really looking to test the
existence of a tapesrty bean that is defined in the Page specification. I don't
think that your solution would work in this case....
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: OGNL: Test for existence?
Posted by "matthew c. mead" <m-...@goof.com>.
I've not tried to do this, but I imagine you could make a function
something like this:
boolean hasPropertyAccessor(String propertyName) throws SecurityException {
try {
return getClass().getMethod("get" + propertyName.substring(0,
1).toUpperCase() + propertyName.substring(1, propertyName.length()), new
Class[] {}) != null;
} catch (NoSuchMethodException e) {
return false;
}
}
Put it in your page class or in its hierarchy somewhere.
Then just call it with the right argument.
-matt
bobby rullo wrote:
>Is there a way to test for the existence of a property or object within a
>collection in OGNL? The docs say you can coerce a null into a boolean false so I
>tried:
>
><span jwcid="@Conditional" condition="ognl:page.beans.delegate" >
> ...
></span>
>
>But that doesn't work (ognl.NoSuchPropertyException). I also tried to be clever
>with:
>
><span jwcid="@Conditional" condition="ognl:page.beans['delegate']" >
> ...
></span>
>
>but that yielded the same results.
>
>Thanks
>
>Bobby
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
--
matthew c. mead
http://www.goof.com/