You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Marcel Schepers <ma...@gmail.com> on 2008/01/26 18:03:46 UTC

How to access the servlet context in AppModule?

How to access the servlet context in AppModule? Tapestry's Spring
integration does not work for the 'services' package. A Spring service is
needed for a custom BindingFactory. My idea was to access Spring's
application context and instantiate a new BindingFactory with the Spring
service as constructor parameter. Any ideas?

Re: How to access the servlet context in AppModule?

Posted by SergeEby <sd...@hotmail.com>.
Not sure what you are doing but the following works fine for me in my
AppModule:

public class AppModule {
...
   public static void contributeAliasOverrides (
                  Configuration<AliasContribution> aConfiguration,
                   @Inject @Service("LabelService") LabelService aService) {
           ....
  }

..
}

In the example above, LabelSevice is a Spring service.


/Serge 


MrclSchprs wrote:
> 
> On Jan 26, 2008 6:34 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:
> 
>> Within the AppModule you can try accessing the following services:
>>
>> 1) WebContextApplicationContext
>> 2) RequestGlobals
>> 3) @Inject @Service("beanName")
>>
>>
> The third option does not work; Tapestry does only inject spring service
> in
> classes residing in 'pages' or 'components' packages. AppModule is in
> 'services'.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-the-servlet-context-in-AppModule--tp15110070p15111202.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: How to access the servlet context in AppModule?

Posted by Marcel Schepers <ma...@gmail.com>.
I think I've got it working, thanks to the overlooked @InjectService. My
module constructor now looks like:

public AppModule(@InjectService("messageDAO") MessageDAO messageDOA) {
   System.out.println("messageDOA2: " + messageDOA);
}

messageDAO is a Spring bean used in 'contributeBindingSource'.

The concept of services, build... methods and contribute... methods is an
area I need to dive into, it is still fuzzy.

Marcel


On Jan 26, 2008 7:41 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:

> Ah.  I think there was a misunderstanding on how AppModule/Tapestry IoC
> works (maybe).  And we also got confused.
>
> Within AppModule/TapestryIoC, the correct annotation is
> @InjectService("name").
>
>
> But you can review the documentation to make sure that we're all on the
> same page:
> http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
>
>
> And another reminder:
>
> Tapestry IoC does not enhance the classes, so the private variable
> enhancement does not work like it works in base/pages/components.
>
> So this will not work!
>
> public class Service {
>   @Inject
>   @Service("name")
>   private Service2 service2;
> }
>
>
>
>
> Marcel Schepers wrote:
> > On Jan 26, 2008 6:34 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:
> >
> >> Within the AppModule you can try accessing the following services:
> >>
> >> 1) WebContextApplicationContext
> >> 2) RequestGlobals
> >> 3) @Inject @Service("beanName")
> >>
> >>
> > The third option does not work; Tapestry does only inject spring service
> in
> > classes residing in 'pages' or 'components' packages. AppModule is in
> > 'services'.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to access the servlet context in AppModule?

Posted by Fernando Padilla <fe...@alum.mit.edu>.
Ah.  I think there was a misunderstanding on how AppModule/Tapestry IoC 
works (maybe).  And we also got confused.

Within AppModule/TapestryIoC, the correct annotation is 
@InjectService("name").


But you can review the documentation to make sure that we're all on the 
same page:
http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html


And another reminder:

Tapestry IoC does not enhance the classes, so the private variable 
enhancement does not work like it works in base/pages/components.

So this will not work!

public class Service {
   @Inject
   @Service("name")
   private Service2 service2;
}




Marcel Schepers wrote:
> On Jan 26, 2008 6:34 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:
> 
>> Within the AppModule you can try accessing the following services:
>>
>> 1) WebContextApplicationContext
>> 2) RequestGlobals
>> 3) @Inject @Service("beanName")
>>
>>
> The third option does not work; Tapestry does only inject spring service in
> classes residing in 'pages' or 'components' packages. AppModule is in
> 'services'.
> 

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


Re: How to access the servlet context in AppModule?

Posted by Marcel Schepers <ma...@gmail.com>.
On Jan 26, 2008 6:34 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:

> Within the AppModule you can try accessing the following services:
>
> 1) WebContextApplicationContext
> 2) RequestGlobals
> 3) @Inject @Service("beanName")
>
>
The third option does not work; Tapestry does only inject spring service in
classes residing in 'pages' or 'components' packages. AppModule is in
'services'.

Re: How to access the servlet context in AppModule?

Posted by Fernando Padilla <fe...@alum.mit.edu>.
Within the AppModule you can try accessing the following services:

1) WebContextApplicationContext
2) RequestGlobals
3) @Inject @Service("beanName")


SergeEby wrote:
> Hey,
> 
> You can pass Spring Services as argument by using the @Inject @Service
> annotations.
> 
> /Serge
> 
> 
> MrclSchprs wrote:
>> How to access the servlet context in AppModule? Tapestry's Spring
>> integration does not work for the 'services' package. A Spring service is
>> needed for a custom BindingFactory. My idea was to access Spring's
>> application context and instantiate a new BindingFactory with the Spring
>> service as constructor parameter. Any ideas?
>>
>>
> 

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


Re: How to access the servlet context in AppModule?

Posted by SergeEby <sd...@hotmail.com>.
Hey,

You can pass Spring Services as argument by using the @Inject @Service
annotations.

/Serge


MrclSchprs wrote:
> 
> How to access the servlet context in AppModule? Tapestry's Spring
> integration does not work for the 'services' package. A Spring service is
> needed for a custom BindingFactory. My idea was to access Spring's
> application context and instantiate a new BindingFactory with the Spring
> service as constructor parameter. Any ideas?
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-the-servlet-context-in-AppModule--tp15110070p15110348.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