You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@mapshed.com.au> on 2010/11/23 05:33:16 UTC
how do i access ComponentResources in a service?
Hi all,
I am writing a service I intend to inject into some pages and components:
public MyPage
{
@Inject private MyService myService;
}
I want MyServiceImpl to have access to ComponentResources
public MyServiceImpl implements MyService
{
@Inject private ComponentResources componentResources;
}
however this causes an exception:
Caused by: java.lang.RuntimeException: No service implements the
interface org.apache.tapestry5.ComponentResources.
at
org.apache.tapestry5.ioc.internal.RegistryImpl.getService(RegistryImpl.java:560)
at
org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getService(ObjectLocatorImpl.java:44)
at
org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl$1.invoke(MasterObjectProviderImpl.java:56)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
... 123 more
Obviously I'm missing some special plumbing in my AppModule.
What is it?
Thanks, Paul.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how do i access ComponentResources in a service?
Posted by Paul Stanton <pa...@mapshed.com.au>.
Thiago,
Using the ComponentSource service methods won't get me a handle to the
current rendering component...
if i'm wrong, can you please provide an example?
I'm trying to find a good re-usable/injectable home for some convenience
methods. eg:
public boolean isCurrentPage(Class<?> pageClass)
{
return getCurrentPageName().equals(getPageName(pageClass));
}
public String getPageName(Class<?> pageClass)
{
return
componentClassResolver.resolvePageClassNameToPageName(pageClass.getName());
}
public String getCurrentPageName()
{
return componentResources.getPageName();
}
There are to be more, some more complex.
p.
On 23/11/2010 10:31 PM, Thiago H. de Paula Figueiredo wrote:
> On Tue, 23 Nov 2010 08:39:03 -0200, Paul Stanton <pa...@mapshed.com.au>
> wrote:
>
>> "@Environmental
>> private ComponentResources componentResources;"
>>
>> I have been unable to get this to work since ComponentResources is
>> not in fact available on the Environment.
>
> I guess your service is being invoked after or before rendering, not
> during it. Try using the ComponentSource service methods. They will
> return a Component instance for you. Don't forget that pages are
> components too. :) Then use its getComponentResources() to get the
> ComponentResources.
>
> By the way, what exactly are you trying to do?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how do i access ComponentResources in a service?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 23 Nov 2010 08:39:03 -0200, Paul Stanton <pa...@mapshed.com.au>
wrote:
> "@Environmental
> private ComponentResources componentResources;"
>
> I have been unable to get this to work since ComponentResources is not
> in fact available on the Environment.
I guess your service is being invoked after or before rendering, not
during it. Try using the ComponentSource service methods. They will return
a Component instance for you. Don't forget that pages are components too.
:) Then use its getComponentResources() to get the ComponentResources.
By the way, what exactly are you trying to do?
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how do i access ComponentResources in a service?
Posted by Paul Stanton <pa...@mapshed.com.au>.
You can inject ComponentResources within a specific component by
injecting it directly.
I asked a similar question earlier in the year, and Thiago & Howard
seemed to think I could get ComponentResources from the Environment and
wire it up via Module.contributeMarkupRenderer &
Module.contributePartialMarkupRenderer.
see posts titled "how to contribute a 'component context' service"
Howard:
"Best bet is to check TapestryModule for examples. Methods
contributeMarkupRenderer() and contributePartialMarkupRenderer()."
Thiago:
"ComponentResources ins't a service. There's class transformation
applied to component and pages classes that inject it. You should get it
from the Environment service by using the peek() or peekRequired()
methods. "
Thiago:
"@Environmental
private ComponentResources componentResources;"
I have been unable to get this to work since ComponentResources is not
in fact available on the Environment.
I guess this is a revival of that thread, and what I'm really asking is
... how do i create a Something (Service/Environmental/Whatever) which
is available to a component (within the scope of the component) which
has access to ComponentResources as well as ComponentClassResolver and
some other 'render time' type stuff.
thanks, Paul.
On 23/11/2010 8:42 PM, Christophe Cordenier wrote:
> Hi,
>
> ComponentResources is not a service, its related to a Component. You can get
> the ComponentResources of a specific component by injecting the
> ComponentSource service and call the getComponentResources() on it
>
> I remember a thread already exists on this, have a look on markmail.
>
> Christophe.
>
> 2010/11/23 Paul Stanton<pa...@mapshed.com.au>
>
>> Hi all,
>>
>> I am writing a service I intend to inject into some pages and components:
>>
>> public MyPage
>> {
>> @Inject private MyService myService;
>> }
>>
>> I want MyServiceImpl to have access to ComponentResources
>>
>> public MyServiceImpl implements MyService
>> {
>> @Inject private ComponentResources componentResources;
>> }
>>
>> however this causes an exception:
>>
>> Caused by: java.lang.RuntimeException: No service implements the interface
>> org.apache.tapestry5.ComponentResources.
>> at
>> org.apache.tapestry5.ioc.internal.RegistryImpl.getService(RegistryImpl.java:560)
>> at
>> org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getService(ObjectLocatorImpl.java:44)
>> at
>> org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl$1.invoke(MasterObjectProviderImpl.java:56)
>> at
>> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
>> ... 123 more
>>
>> Obviously I'm missing some special plumbing in my AppModule.
>>
>> What is it?
>>
>> Thanks, Paul.
>>
>> ---------------------------------------------------------------------
>> 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: how do i access ComponentResources in a service?
Posted by Christophe Cordenier <ch...@gmail.com>.
Hi,
ComponentResources is not a service, its related to a Component. You can get
the ComponentResources of a specific component by injecting the
ComponentSource service and call the getComponentResources() on it
I remember a thread already exists on this, have a look on markmail.
Christophe.
2010/11/23 Paul Stanton <pa...@mapshed.com.au>
> Hi all,
>
> I am writing a service I intend to inject into some pages and components:
>
> public MyPage
> {
> @Inject private MyService myService;
> }
>
> I want MyServiceImpl to have access to ComponentResources
>
> public MyServiceImpl implements MyService
> {
> @Inject private ComponentResources componentResources;
> }
>
> however this causes an exception:
>
> Caused by: java.lang.RuntimeException: No service implements the interface
> org.apache.tapestry5.ComponentResources.
> at
> org.apache.tapestry5.ioc.internal.RegistryImpl.getService(RegistryImpl.java:560)
> at
> org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getService(ObjectLocatorImpl.java:44)
> at
> org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl$1.invoke(MasterObjectProviderImpl.java:56)
> at
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
> ... 123 more
>
> Obviously I'm missing some special plumbing in my AppModule.
>
> What is it?
>
> Thanks, Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Regards,
Christophe Cordenier.
Committer on Apache Tapestry 5
Co-creator of wooki @wookicentral.com