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 <[EMAIL PROTECTED]> >>>>>> 05.05.2008 15:53 >>>>>> Bitte antworten an >>>>>> "Tapestry users" <users@tapestry.apache.org> >>>>>> >>>>>> >>>>>> An >>>>>> tapestry Tapestry <[EMAIL PROTECTED]> >>>>>> 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: [EMAIL PROTECTED] >>>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>>> >>>>>> >>>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>> >>>>> >>>>> >>>> >>>> -- >>>> 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: [EMAIL PROTECTED] >>>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> >> >> -- >> 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: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]