You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Richard Hoberman <ri...@sadalbari.com> on 2008/08/15 17:43:49 UTC

[T5] Expansions - calling page methods via componentResources

Hi

Why does something like this (in a component template):

${componentResources.page.getTitle()}

throw an exception like this:

Could not convert 'getTitle()' into a component parameter binding: No public
method 'getTitle()' in class com.example.components.Layout (within property
expression 'getTitle()').


Where the page class has a simple (non-property) method:

public class MyPage {

...

   public String getTitle() {
        return "title";
   }
...
}

It works fine from within the page and the expansion
${componentResources.page} shows the expected page class.

Thanks

Richard Hoberman
-- 
View this message in context: http://www.nabble.com/-T5--Expansions---calling-page-methods-via-componentResources-tp19000908p19000908.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Expansions - calling page methods via componentResources

Posted by Howard Lewis Ship <hl...@gmail.com>.
Sorry to say, this won't necessarily work.

componentResources.getPage()'s return type is Component.

Component does not have a title property.

MyPage (or whatever) does have such a property, and is modified at
runtime to implement Component.

The PropertyConduit (the underlying technology that implements the
property expressions used by the prop: binding, and expansions) ...
anyway, it works entirely in terms of the declared type, not (as OGNL
does) the actual type.  This allows Tapestry to write bytecode for
property expressions that works in a type safe manner.

One option for what you need is:

@InjectContainer
@Property
private MyPage page;

This goes in the component.

You can then use ${page.title}.  In this case, the @InjectContainer
gets the container object (MyPage) and casts it as it assigns it to
the field.  @Property then provides getters and setters, of type
MyPage (not type Component).

Well lookie there ... the right solution is actually shorter and
easier!  That's the Tapestry way.

On Fri, Aug 15, 2008 at 11:42 AM, Jonathan Barker
<jo...@gmail.com> wrote:
> You want to use ${componentResources.page.title}
>
> Your "non-property" method still looks like a property method, and that's
> what the T5 expansions handle well.
>
>
>> -----Original Message-----
>> From: Richard Hoberman [mailto:richard.hoberman@sadalbari.com]
>> Sent: Friday, August 15, 2008 11:44
>> To: users@tapestry.apache.org
>> Subject: [T5] Expansions - calling page methods via componentResources
>>
>>
>> Hi
>>
>> Why does something like this (in a component template):
>>
>> ${componentResources.page.getTitle()}
>>
>> throw an exception like this:
>>
>> Could not convert 'getTitle()' into a component parameter binding: No
>> public
>> method 'getTitle()' in class com.example.components.Layout (within
>> property
>> expression 'getTitle()').
>>
>>
>> Where the page class has a simple (non-property) method:
>>
>> public class MyPage {
>>
>> ...
>>
>>    public String getTitle() {
>>         return "title";
>>    }
>> ...
>> }
>>
>> It works fine from within the page and the expansion
>> ${componentResources.page} shows the expected page class.
>>
>> Thanks
>>
>> Richard Hoberman
>> --
>> View this message in context: http://www.nabble.com/-T5--Expansions---
>> calling-page-methods-via-componentResources-tp19000908p19000908.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: [T5] Expansions - calling page methods via componentResources

Posted by Jonathan Barker <jo...@gmail.com>.
You want to use ${componentResources.page.title}

Your "non-property" method still looks like a property method, and that's
what the T5 expansions handle well.


> -----Original Message-----
> From: Richard Hoberman [mailto:richard.hoberman@sadalbari.com]
> Sent: Friday, August 15, 2008 11:44
> To: users@tapestry.apache.org
> Subject: [T5] Expansions - calling page methods via componentResources
> 
> 
> Hi
> 
> Why does something like this (in a component template):
> 
> ${componentResources.page.getTitle()}
> 
> throw an exception like this:
> 
> Could not convert 'getTitle()' into a component parameter binding: No
> public
> method 'getTitle()' in class com.example.components.Layout (within
> property
> expression 'getTitle()').
> 
> 
> Where the page class has a simple (non-property) method:
> 
> public class MyPage {
> 
> ...
> 
>    public String getTitle() {
>         return "title";
>    }
> ...
> }
> 
> It works fine from within the page and the expansion
> ${componentResources.page} shows the expected page class.
> 
> Thanks
> 
> Richard Hoberman
> --
> View this message in context: http://www.nabble.com/-T5--Expansions---
> calling-page-methods-via-componentResources-tp19000908p19000908.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org