You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Shing Hing Man <ma...@yahoo.com> on 2008/05/05 15:53:52 UTC

Tap 5.0.11 : How to get page instance from page

Usually, I could use the following to inject a page
into another  page

  @InjectPage
  private DetailsPage  details;
  
How to retrieve an instance of a page if I am given
the logical name of a page as a String variable ?

In Tap 4, I would use RequestCycle.getPage(pageName).

Thanks in advance for any asistance!

Shing

Home page : http://www.lombok.demon.co.uk/



      ___________________________________________________________ 
Yahoo! For Good. Give and get cool things for free, reduce waste and help our planet. Plus find hidden Yahoo! treasure 

http://green.yahoo.com/uk/earth-day/

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


Re: Tap 5.0.11 : How to get page instance from page

Posted by Marcelo Lotif <ml...@gmail.com>.
Raulmt,
I'm using exactly the same code as you with the solution #2 from
Robert and it's working very well for me. Maybe you should try it
first.

2008/6/3 Robert Zeigler <ro...@scazdl.org>:
> This is by-product of the live class reloading, and not related to the
> instrumentation, per se.
> Two classes in different classloaders are not equal. In this case, you're
> casting the component object, whose class is in the "discardable"
> classloader (which handles page and component classes) to the "MyPage" class
> which is in the non-discardable class loader (which handles anything not a
> page, component, or mixin).  There are two workarounds to your problem.
> 1) You code will work "as is" if you put it into a page or component. In
> that case, you could try passing the page or component to the service,
> instead of trying to load the page or component in the service.  Or...
> 2) Have your page/pages implement a common interface (the interface class
> should be stored outside of the page/component/mixin sub-packages). Then
> cast to your interface, instead of to the actual page.  Personally, I think
> this is a cleaner solution, anyway (knowing the property you want to set
> beforehand, but not knowing the actual class/page name until runtime smells
> like you want an interface, anyway).
>
> Robert
>
> On Jun 2, 2008, at 6/25:18 PM , raulmt wrote:
>
>>
>> No, I need to do this in a service... but even in a page, i have the page
>> class in a String at runtime, so I can't declare a property and use the
>> InjectPage like that....
>>
>> Regards.
>>
>>
>> Robert Zeigler wrote:
>>>
>>> Is this in a component or page class? If so, the answer is:
>>>
>>> @InjectPage
>>> private MyPage page;
>>> ...
>>>
>>> page.setSomething("");
>>>
>>> Robert
>>>
>>> On Jun 2, 2008, at 6/25:04 PM , raulmt wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> I'm trying to obtain a page from it's name to set a property on it.
>>>> I'm
>>>> trying something like this:
>>>>
>>>> Component page = componentSource.getPage("MyPage");
>>>> MyPage myPage = (MyPage)page;
>>>> myPage.setSomething("");
>>>>
>>>> This code fails in the cast, despite a
>>>>
>>>> System.out.println(page.getClass().getName());
>>>>
>>>> prints the expected page class (com.myapp.pages.MyPage).... I assume
>>>> is
>>>> because all the instrumentation T5 does to the pages, but is there a
>>>> way to
>>>> obtain a page from its name and then set a property that the
>>>> "original"
>>>> class has??
>>>>
>>>> The only workaround i've found is to call the method setSomething with
>>>> reflection, without casting it to MyPage, but it would be really
>>>> nice not to
>>>> use reflection for this....
>>>>
>>>> Regards.
>>>>
>>>>
>>>> Filip S. Adamsen-2 wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> RequestPageCache is an internal service, it's better to use
>>>>> ComponentSource instead. It has methods to get a component or page by
>>>>> logical name.
>>>>>
>>>>>
>>>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
>>>>>
>>>>> -Filip
>>>>>
>>>>> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>>>>>>
>>>>>> @Inject
>>>>>> private RequestPageCache pageCache;
>>>>>>
>>>>>> pageCache.get(logicalName)
>>>>>>
>>>>>>
>>>>>> g,
>>>>>> kris
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Shing Hing Man <ma...@yahoo.com>
>>>>>> 05.05.2008 15:53
>>>>>> Bitte antworten an
>>>>>> "Tapestry users" <us...@tapestry.apache.org>
>>>>>>
>>>>>>
>>>>>> An
>>>>>> tapestry Tapestry <ta...@jakarta.apache.org>
>>>>>> Kopie
>>>>>>
>>>>>> Thema
>>>>>> Tap 5.0.11 : How to get page instance  from page
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Usually, I could use the following to inject a page
>>>>>> into another  page
>>>>>>
>>>>>> @InjectPage
>>>>>> private DetailsPage  details;
>>>>>>
>>>>>> How to retrieve an instance of a page if I am given
>>>>>> the logical name of a page as a String variable ?
>>>>>>
>>>>>> In Tap 4, I would use RequestCycle.getPage(pageName).
>>>>>>
>>>>>> Thanks in advance for any asistance!
>>>>>>
>>>>>> Shing
>>>>>>
>>>>>> Home page : http://www.lombok.demon.co.uk/
>>>>>>
>>>>>>
>>>>>>
>>>>>>   ___________________________________________________________
>>>>>> Yahoo! For Good. Give and get cool things for free, reduce waste
>>>>>> and help
>>>>>> our planet. Plus find hidden Yahoo! treasure
>>>>>>
>>>>>> http://green.yahoo.com/uk/earth-day/
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>>
>>>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17612066.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
>
>



-- 
Atenciosamente,
Marcelo Lotif

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


Re: Tap 5.0.11 : How to get page instance from page

Posted by raulmt <ra...@gmail.com>.
Thanks Robert!!

I tried 2) before, but I left the interface in the same package
([...].pages).... now I move it to another package like you said and it
works perfectly :)

And thanks for the explanation of the classloaders, it is all clear now.

Regards.


Robert Zeigler wrote:
> 
> This is by-product of the live class reloading, and not related to the  
> instrumentation, per se.
> Two classes in different classloaders are not equal. In this case,  
> you're casting the component object, whose class is in the  
> "discardable" classloader (which handles page and component classes)  
> to the "MyPage" class which is in the non-discardable class loader  
> (which handles anything not a page, component, or mixin).  There are  
> two workarounds to your problem.
> 1) You code will work "as is" if you put it into a page or component.  
> In that case, you could try passing the page or component to the  
> service, instead of trying to load the page or component in the  
> service.  Or...
> 2) Have your page/pages implement a common interface (the interface  
> class should be stored outside of the page/component/mixin sub- 
> packages). Then cast to your interface, instead of to the actual  
> page.  Personally, I think this is a cleaner solution, anyway (knowing  
> the property you want to set beforehand, but not knowing the actual  
> class/page name until runtime smells like you want an interface,  
> anyway).
> 
> Robert
> 
> On Jun 2, 2008, at 6/25:18 PM , raulmt wrote:
> 
>>
>> No, I need to do this in a service... but even in a page, i have the  
>> page
>> class in a String at runtime, so I can't declare a property and use  
>> the
>> InjectPage like that....
>>
>> Regards.
>>
>>
>> Robert Zeigler wrote:
>>>
>>> Is this in a component or page class? If so, the answer is:
>>>
>>> @InjectPage
>>> private MyPage page;
>>> ...
>>>
>>> page.setSomething("");
>>>
>>> Robert
>>>
>>> On Jun 2, 2008, at 6/25:04 PM , raulmt wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> I'm trying to obtain a page from it's name to set a property on it.
>>>> I'm
>>>> trying something like this:
>>>>
>>>> Component page = componentSource.getPage("MyPage");
>>>> MyPage myPage = (MyPage)page;
>>>> myPage.setSomething("");
>>>>
>>>> This code fails in the cast, despite a
>>>>
>>>> System.out.println(page.getClass().getName());
>>>>
>>>> prints the expected page class (com.myapp.pages.MyPage).... I assume
>>>> is
>>>> because all the instrumentation T5 does to the pages, but is there a
>>>> way to
>>>> obtain a page from its name and then set a property that the
>>>> "original"
>>>> class has??
>>>>
>>>> The only workaround i've found is to call the method setSomething  
>>>> with
>>>> reflection, without casting it to MyPage, but it would be really
>>>> nice not to
>>>> use reflection for this....
>>>>
>>>> Regards.
>>>>
>>>>
>>>> Filip S. Adamsen-2 wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> RequestPageCache is an internal service, it's better to use
>>>>> ComponentSource instead. It has methods to get a component or  
>>>>> page by
>>>>> logical name.
>>>>>
>>>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
>>>>>
>>>>> -Filip
>>>>>
>>>>> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>>>>>> @Inject
>>>>>> private RequestPageCache pageCache;
>>>>>>
>>>>>> pageCache.get(logicalName)
>>>>>>
>>>>>>
>>>>>> g,
>>>>>> kris
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Shing Hing Man <ma...@yahoo.com>
>>>>>> 05.05.2008 15:53
>>>>>> Bitte antworten an
>>>>>> "Tapestry users" <us...@tapestry.apache.org>
>>>>>>
>>>>>>
>>>>>> An
>>>>>> tapestry Tapestry <ta...@jakarta.apache.org>
>>>>>> Kopie
>>>>>>
>>>>>> Thema
>>>>>> Tap 5.0.11 : How to get page instance  from page
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Usually, I could use the following to inject a page
>>>>>> into another  page
>>>>>>
>>>>>> @InjectPage
>>>>>> private DetailsPage  details;
>>>>>>
>>>>>> How to retrieve an instance of a page if I am given
>>>>>> the logical name of a page as a String variable ?
>>>>>>
>>>>>> In Tap 4, I would use RequestCycle.getPage(pageName).
>>>>>>
>>>>>> Thanks in advance for any asistance!
>>>>>>
>>>>>> Shing
>>>>>>
>>>>>> Home page : http://www.lombok.demon.co.uk/
>>>>>>
>>>>>>
>>>>>>
>>>>>>    ___________________________________________________________
>>>>>> Yahoo! For Good. Give and get cool things for free, reduce waste
>>>>>> and help
>>>>>> our planet. Plus find hidden Yahoo! treasure
>>>>>>
>>>>>> http://green.yahoo.com/uk/earth-day/
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>>>>>
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> View this message in context:
>>>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17612066.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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17626327.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: Tap 5.0.11 : How to get page instance from page

Posted by Robert Zeigler <ro...@scazdl.org>.
This is by-product of the live class reloading, and not related to the  
instrumentation, per se.
Two classes in different classloaders are not equal. In this case,  
you're casting the component object, whose class is in the  
"discardable" classloader (which handles page and component classes)  
to the "MyPage" class which is in the non-discardable class loader  
(which handles anything not a page, component, or mixin).  There are  
two workarounds to your problem.
1) You code will work "as is" if you put it into a page or component.  
In that case, you could try passing the page or component to the  
service, instead of trying to load the page or component in the  
service.  Or...
2) Have your page/pages implement a common interface (the interface  
class should be stored outside of the page/component/mixin sub- 
packages). Then cast to your interface, instead of to the actual  
page.  Personally, I think this is a cleaner solution, anyway (knowing  
the property you want to set beforehand, but not knowing the actual  
class/page name until runtime smells like you want an interface,  
anyway).

Robert

On Jun 2, 2008, at 6/25:18 PM , raulmt wrote:

>
> No, I need to do this in a service... but even in a page, i have the  
> page
> class in a String at runtime, so I can't declare a property and use  
> the
> InjectPage like that....
>
> Regards.
>
>
> Robert Zeigler wrote:
>>
>> Is this in a component or page class? If so, the answer is:
>>
>> @InjectPage
>> private MyPage page;
>> ...
>>
>> page.setSomething("");
>>
>> Robert
>>
>> On Jun 2, 2008, at 6/25:04 PM , raulmt wrote:
>>
>>>
>>> Hi,
>>>
>>> I'm trying to obtain a page from it's name to set a property on it.
>>> I'm
>>> trying something like this:
>>>
>>> Component page = componentSource.getPage("MyPage");
>>> MyPage myPage = (MyPage)page;
>>> myPage.setSomething("");
>>>
>>> This code fails in the cast, despite a
>>>
>>> System.out.println(page.getClass().getName());
>>>
>>> prints the expected page class (com.myapp.pages.MyPage).... I assume
>>> is
>>> because all the instrumentation T5 does to the pages, but is there a
>>> way to
>>> obtain a page from its name and then set a property that the
>>> "original"
>>> class has??
>>>
>>> The only workaround i've found is to call the method setSomething  
>>> with
>>> reflection, without casting it to MyPage, but it would be really
>>> nice not to
>>> use reflection for this....
>>>
>>> Regards.
>>>
>>>
>>> Filip S. Adamsen-2 wrote:
>>>>
>>>> Hi,
>>>>
>>>> RequestPageCache is an internal service, it's better to use
>>>> ComponentSource instead. It has methods to get a component or  
>>>> page by
>>>> logical name.
>>>>
>>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
>>>>
>>>> -Filip
>>>>
>>>> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>>>>> @Inject
>>>>> private RequestPageCache pageCache;
>>>>>
>>>>> pageCache.get(logicalName)
>>>>>
>>>>>
>>>>> g,
>>>>> kris
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Shing Hing Man <ma...@yahoo.com>
>>>>> 05.05.2008 15:53
>>>>> Bitte antworten an
>>>>> "Tapestry users" <us...@tapestry.apache.org>
>>>>>
>>>>>
>>>>> An
>>>>> tapestry Tapestry <ta...@jakarta.apache.org>
>>>>> Kopie
>>>>>
>>>>> Thema
>>>>> Tap 5.0.11 : How to get page instance  from page
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Usually, I could use the following to inject a page
>>>>> into another  page
>>>>>
>>>>> @InjectPage
>>>>> private DetailsPage  details;
>>>>>
>>>>> How to retrieve an instance of a page if I am given
>>>>> the logical name of a page as a String variable ?
>>>>>
>>>>> In Tap 4, I would use RequestCycle.getPage(pageName).
>>>>>
>>>>> Thanks in advance for any asistance!
>>>>>
>>>>> Shing
>>>>>
>>>>> Home page : http://www.lombok.demon.co.uk/
>>>>>
>>>>>
>>>>>
>>>>>    ___________________________________________________________
>>>>> Yahoo! For Good. Give and get cool things for free, reduce waste
>>>>> and help
>>>>> our planet. Plus find hidden Yahoo! treasure
>>>>>
>>>>> http://green.yahoo.com/uk/earth-day/
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17612066.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


Re: Tap 5.0.11 : How to get page instance from page

Posted by Thiago HP <th...@gmail.com>.
On 6/2/08, raulmt <ra...@gmail.com> wrote:

>  No, I need to do this in a service... but even in a page, i have the page
>  class in a String at runtime, so I can't declare a property and use the
>  InjectPage like that....

Why don't you try to pass a page instance as a parameter to your
method service? Something like:

@InjectPage
private SomePage page;

void example() {
    yourservice.yourMethod(page, otherParameters);
}

-- 
Thiago

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


Re: Tap 5.0.11 : How to get page instance from page

Posted by raulmt <ra...@gmail.com>.
No, I need to do this in a service... but even in a page, i have the page
class in a String at runtime, so I can't declare a property and use the
InjectPage like that....

Regards.


Robert Zeigler wrote:
> 
> Is this in a component or page class? If so, the answer is:
> 
> @InjectPage
> private MyPage page;
> ...
> 
> page.setSomething("");
> 
> Robert
> 
> On Jun 2, 2008, at 6/25:04 PM , raulmt wrote:
> 
>>
>> Hi,
>>
>> I'm trying to obtain a page from it's name to set a property on it.  
>> I'm
>> trying something like this:
>>
>> Component page = componentSource.getPage("MyPage");
>> MyPage myPage = (MyPage)page;
>> myPage.setSomething("");
>>
>> This code fails in the cast, despite a
>>
>> System.out.println(page.getClass().getName());
>>
>> prints the expected page class (com.myapp.pages.MyPage).... I assume  
>> is
>> because all the instrumentation T5 does to the pages, but is there a  
>> way to
>> obtain a page from its name and then set a property that the  
>> "original"
>> class has??
>>
>> The only workaround i've found is to call the method setSomething with
>> reflection, without casting it to MyPage, but it would be really  
>> nice not to
>> use reflection for this....
>>
>> Regards.
>>
>>
>> Filip S. Adamsen-2 wrote:
>>>
>>> Hi,
>>>
>>> RequestPageCache is an internal service, it's better to use
>>> ComponentSource instead. It has methods to get a component or page by
>>> logical name.
>>>
>>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
>>>
>>> -Filip
>>>
>>> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>>>> @Inject
>>>> private RequestPageCache pageCache;
>>>>
>>>> pageCache.get(logicalName)
>>>>
>>>>
>>>> g,
>>>> kris
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Shing Hing Man <ma...@yahoo.com>
>>>> 05.05.2008 15:53
>>>> Bitte antworten an
>>>> "Tapestry users" <us...@tapestry.apache.org>
>>>>
>>>>
>>>> An
>>>> tapestry Tapestry <ta...@jakarta.apache.org>
>>>> Kopie
>>>>
>>>> Thema
>>>> Tap 5.0.11 : How to get page instance  from page
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Usually, I could use the following to inject a page
>>>> into another  page
>>>>
>>>>  @InjectPage
>>>>  private DetailsPage  details;
>>>>
>>>> How to retrieve an instance of a page if I am given
>>>> the logical name of a page as a String variable ?
>>>>
>>>> In Tap 4, I would use RequestCycle.getPage(pageName).
>>>>
>>>> Thanks in advance for any asistance!
>>>>
>>>> Shing
>>>>
>>>> Home page : http://www.lombok.demon.co.uk/
>>>>
>>>>
>>>>
>>>>      ___________________________________________________________
>>>> Yahoo! For Good. Give and get cool things for free, reduce waste  
>>>> and help
>>>> our planet. Plus find hidden Yahoo! treasure
>>>>
>>>> http://green.yahoo.com/uk/earth-day/
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17612066.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: Tap 5.0.11 : How to get page instance from page

Posted by Robert Zeigler <ro...@scazdl.org>.
Is this in a component or page class? If so, the answer is:

@InjectPage
private MyPage page;
...

page.setSomething("");

Robert

On Jun 2, 2008, at 6/25:04 PM , raulmt wrote:

>
> Hi,
>
> I'm trying to obtain a page from it's name to set a property on it.  
> I'm
> trying something like this:
>
> Component page = componentSource.getPage("MyPage");
> MyPage myPage = (MyPage)page;
> myPage.setSomething("");
>
> This code fails in the cast, despite a
>
> System.out.println(page.getClass().getName());
>
> prints the expected page class (com.myapp.pages.MyPage).... I assume  
> is
> because all the instrumentation T5 does to the pages, but is there a  
> way to
> obtain a page from its name and then set a property that the  
> "original"
> class has??
>
> The only workaround i've found is to call the method setSomething with
> reflection, without casting it to MyPage, but it would be really  
> nice not to
> use reflection for this....
>
> Regards.
>
>
> Filip S. Adamsen-2 wrote:
>>
>> Hi,
>>
>> RequestPageCache is an internal service, it's better to use
>> ComponentSource instead. It has methods to get a component or page by
>> logical name.
>>
>> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
>>
>> -Filip
>>
>> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>>> @Inject
>>> private RequestPageCache pageCache;
>>>
>>> pageCache.get(logicalName)
>>>
>>>
>>> g,
>>> kris
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Shing Hing Man <ma...@yahoo.com>
>>> 05.05.2008 15:53
>>> Bitte antworten an
>>> "Tapestry users" <us...@tapestry.apache.org>
>>>
>>>
>>> An
>>> tapestry Tapestry <ta...@jakarta.apache.org>
>>> Kopie
>>>
>>> Thema
>>> Tap 5.0.11 : How to get page instance  from page
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Usually, I could use the following to inject a page
>>> into another  page
>>>
>>>  @InjectPage
>>>  private DetailsPage  details;
>>>
>>> How to retrieve an instance of a page if I am given
>>> the logical name of a page as a String variable ?
>>>
>>> In Tap 4, I would use RequestCycle.getPage(pageName).
>>>
>>> Thanks in advance for any asistance!
>>>
>>> Shing
>>>
>>> Home page : http://www.lombok.demon.co.uk/
>>>
>>>
>>>
>>>      ___________________________________________________________
>>> Yahoo! For Good. Give and get cool things for free, reduce waste  
>>> and help
>>> our planet. Plus find hidden Yahoo! treasure
>>>
>>> http://green.yahoo.com/uk/earth-day/
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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


Re: Tap 5.0.11 : How to get page instance from page

Posted by raulmt <ra...@gmail.com>.
Hi,

I'm trying to obtain a page from it's name to set a property on it. I'm
trying something like this:

Component page = componentSource.getPage("MyPage");
MyPage myPage = (MyPage)page;
myPage.setSomething("");

This code fails in the cast, despite a 

System.out.println(page.getClass().getName());

prints the expected page class (com.myapp.pages.MyPage).... I assume is
because all the instrumentation T5 does to the pages, but is there a way to
obtain a page from its name and then set a property that the "original"
class has??

The only workaround i've found is to call the method setSomething with
reflection, without casting it to MyPage, but it would be really nice not to
use reflection for this....

Regards.


Filip S. Adamsen-2 wrote:
> 
> Hi,
> 
> RequestPageCache is an internal service, it's better to use 
> ComponentSource instead. It has methods to get a component or page by 
> logical name.
> 
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
> 
> -Filip
> 
> On 2008-05-05 16:01, Kristian Marinkovic wrote:
>> @Inject
>> private RequestPageCache pageCache;
>> 
>> pageCache.get(logicalName)
>> 
>> 
>> g,
>> kris
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Shing Hing Man <ma...@yahoo.com> 
>> 05.05.2008 15:53
>> Bitte antworten an
>> "Tapestry users" <us...@tapestry.apache.org>
>> 
>> 
>> An
>> tapestry Tapestry <ta...@jakarta.apache.org>
>> Kopie
>> 
>> Thema
>> Tap 5.0.11 : How to get page instance  from page
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Usually, I could use the following to inject a page
>> into another  page
>> 
>>   @InjectPage
>>   private DetailsPage  details;
>>  
>> How to retrieve an instance of a page if I am given
>> the logical name of a page as a String variable ?
>> 
>> In Tap 4, I would use RequestCycle.getPage(pageName).
>> 
>> Thanks in advance for any asistance!
>> 
>> Shing
>> 
>> Home page : http://www.lombok.demon.co.uk/
>> 
>> 
>> 
>>       ___________________________________________________________ 
>> Yahoo! For Good. Give and get cool things for free, reduce waste and help 
>> our planet. Plus find hidden Yahoo! treasure 
>> 
>> http://green.yahoo.com/uk/earth-day/
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tap-5.0.11-%3A-How-to-get-page-instance--from-page-tp17062196p17611843.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: Tap 5.0.11 : How to get page instance from page

Posted by Shing Hing Man <ma...@yahoo.com>.
Thanks for all the replies!
 I have tried it and it works.

Shing


--- "Filip S. Adamsen" <fs...@fsadev.com> wrote:

> Hi,
> 
> RequestPageCache is an internal service, it's better
> to use 
> ComponentSource instead. It has methods to get a
> component or page by 
> logical name.
> 
>
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html
> 
> -Filip
> 
> On 2008-05-05 16:01, Kristian Marinkovic wrote:
> > @Inject
> > private RequestPageCache pageCache;
> > 
> > pageCache.get(logicalName)
> > 
> > 
> > g,
> > kris
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > Shing Hing Man <ma...@yahoo.com> 
> > 05.05.2008 15:53
> > Bitte antworten an
> > "Tapestry users" <us...@tapestry.apache.org>
> > 
> > 
> > An
> > tapestry Tapestry
> <ta...@jakarta.apache.org>
> > Kopie
> > 
> > Thema
> > Tap 5.0.11 : How to get page instance  from page
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > Usually, I could use the following to inject a
> page
> > into another  page
> > 
> >   @InjectPage
> >   private DetailsPage  details;
> >  
> > How to retrieve an instance of a page if I am
> given
> > the logical name of a page as a String variable ?
> > 
> > In Tap 4, I would use
> RequestCycle.getPage(pageName).
> > 
> > Thanks in advance for any asistance!
> > 
> > Shing
> > 
> > Home page : http://www.lombok.demon.co.uk/
> > 
> > 
> > 
> >      
>
___________________________________________________________
> 
> > Yahoo! For Good. Give and get cool things for
> free, reduce waste and help 
> > our planet. Plus find hidden Yahoo! treasure 
> > 
> > http://green.yahoo.com/uk/earth-day/
> > 
> >
>
---------------------------------------------------------------------
> > 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
> 
> 


Home page : http://www.lombok.demon.co.uk/



      ___________________________________________________________ 
Yahoo! For Good. Give and get cool things for free, reduce waste and help our planet. Plus find hidden Yahoo! treasure 

http://green.yahoo.com/uk/earth-day/

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


Re: Tap 5.0.11 : How to get page instance from page

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
thank you for the hint, didn't even notice this service .... 
i saw that the BeanBlockSource service was using RequestPageCache, 
and so did i :)

g,
kris




"Filip S. Adamsen" <fs...@fsadev.com> 
05.05.2008 16:41
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: Tap 5.0.11 : How to get page instance  from page







Hi,

RequestPageCache is an internal service, it's better to use 
ComponentSource instead. It has methods to get a component or page by 
logical name.

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html


-Filip

On 2008-05-05 16:01, Kristian Marinkovic wrote:
> @Inject
> private RequestPageCache pageCache;
> 
> pageCache.get(logicalName)
> 
> 
> g,
> kris
> 
> 
> 
> 
> 
> 
> 
> Shing Hing Man <ma...@yahoo.com> 
> 05.05.2008 15:53
> Bitte antworten an
> "Tapestry users" <us...@tapestry.apache.org>
> 
> 
> An
> tapestry Tapestry <ta...@jakarta.apache.org>
> Kopie
> 
> Thema
> Tap 5.0.11 : How to get page instance  from page
> 
> 
> 
> 
> 
> 
> 
> Usually, I could use the following to inject a page
> into another  page
> 
>   @InjectPage
>   private DetailsPage  details;
> 
> How to retrieve an instance of a page if I am given
> the logical name of a page as a String variable ?
> 
> In Tap 4, I would use RequestCycle.getPage(pageName).
> 
> Thanks in advance for any asistance!
> 
> Shing
> 
> Home page : http://www.lombok.demon.co.uk/
> 
> 
> 
>       ___________________________________________________________ 
> Yahoo! For Good. Give and get cool things for free, reduce waste and 
help 
> our planet. Plus find hidden Yahoo! treasure 
> 
> http://green.yahoo.com/uk/earth-day/
> 
> ---------------------------------------------------------------------
> 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



Re: Tap 5.0.11 : How to get page instance from page

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,

RequestPageCache is an internal service, it's better to use 
ComponentSource instead. It has methods to get a component or page by 
logical name.

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ComponentSource.html

-Filip

On 2008-05-05 16:01, Kristian Marinkovic wrote:
> @Inject
> private RequestPageCache pageCache;
> 
> pageCache.get(logicalName)
> 
> 
> g,
> kris
> 
> 
> 
> 
> 
> 
> 
> Shing Hing Man <ma...@yahoo.com> 
> 05.05.2008 15:53
> Bitte antworten an
> "Tapestry users" <us...@tapestry.apache.org>
> 
> 
> An
> tapestry Tapestry <ta...@jakarta.apache.org>
> Kopie
> 
> Thema
> Tap 5.0.11 : How to get page instance  from page
> 
> 
> 
> 
> 
> 
> 
> Usually, I could use the following to inject a page
> into another  page
> 
>   @InjectPage
>   private DetailsPage  details;
>  
> How to retrieve an instance of a page if I am given
> the logical name of a page as a String variable ?
> 
> In Tap 4, I would use RequestCycle.getPage(pageName).
> 
> Thanks in advance for any asistance!
> 
> Shing
> 
> Home page : http://www.lombok.demon.co.uk/
> 
> 
> 
>       ___________________________________________________________ 
> Yahoo! For Good. Give and get cool things for free, reduce waste and help 
> our planet. Plus find hidden Yahoo! treasure 
> 
> http://green.yahoo.com/uk/earth-day/
> 
> ---------------------------------------------------------------------
> 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


RE: Tap 5.0.11 : How to get page instance from page

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
@Inject
private RequestPageCache pageCache;

pageCache.get(logicalName)


g,
kris







Shing Hing Man <ma...@yahoo.com> 
05.05.2008 15:53
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
tapestry Tapestry <ta...@jakarta.apache.org>
Kopie

Thema
Tap 5.0.11 : How to get page instance  from page







Usually, I could use the following to inject a page
into another  page

  @InjectPage
  private DetailsPage  details;
 
How to retrieve an instance of a page if I am given
the logical name of a page as a String variable ?

In Tap 4, I would use RequestCycle.getPage(pageName).

Thanks in advance for any asistance!

Shing

Home page : http://www.lombok.demon.co.uk/



      ___________________________________________________________ 
Yahoo! For Good. Give and get cool things for free, reduce waste and help 
our planet. Plus find hidden Yahoo! treasure 

http://green.yahoo.com/uk/earth-day/

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