Getting ServletContext inside service

View: New views
4 Messages — Rating Filter:   Alert me  

Getting ServletContext inside service

by Stefan-114 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

is there a way to get access to the ServletContext inside a service  
bean?

I like to configure some parameters within the web.xml which i need in  
some services.
How can i retrieve these parameters?
Injecting "ApplicationGlobals" does not work.

Where is my mistake?

Thanks in advance.
Stefan

smime.p7s (3K) Download Attachment

Re: Getting ServletContext inside service

by Benny Law :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Stefan,

Try injecting org.apache.tapestry5.services.Context into your service and
use its getInitParameter() method to retrieve your context parameters.

Regards,

Benny Law

On Fri, Oct 30, 2009 at 3:56 PM, Stefan <stefan@...> wrote:

> Hi,
>
> is there a way to get access to the ServletContext inside a service bean?
>
> I like to configure some parameters within the web.xml which i need in some
> services.
> How can i retrieve these parameters?
> Injecting "ApplicationGlobals" does not work.
>
> Where is my mistake?
>
> Thanks in advance.
> Stefan

Re: Getting ServletContext inside service

by Stefan-114 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Benny,

i've tried that too, but it does not work.
The context is null.

Here's how i do it:

@Inject
private org.apache.tapestry5.services.Context context;

Should that work?

Stefan



Am 30.10.2009 um 23:50 schrieb Benny Law:

> Hi Stefan,
>
> Try injecting org.apache.tapestry5.services.Context into your  
> service and
> use its getInitParameter() method to retrieve your context parameters.
>
> Regards,
>
> Benny Law
>
> On Fri, Oct 30, 2009 at 3:56 PM, Stefan <stefan@...> wrote:
>
>> Hi,
>>
>> is there a way to get access to the ServletContext inside a service  
>> bean?
>>
>> I like to configure some parameters within the web.xml which i need  
>> in some
>> services.
>> How can i retrieve these parameters?
>> Injecting "ApplicationGlobals" does not work.
>>
>> Where is my mistake?
>>
>> Thanks in advance.
>> Stefan


smime.p7s (3K) Download Attachment

Re: Getting ServletContext inside service

by Benny Law :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That depends on how your service is managed. I bind my service using the
static binder in AppModule and use constructor arguments to inject what I
need into my service object, and this works for me.

Benny

On Sat, Oct 31, 2009 at 4:47 AM, Stefan <stefan@...> wrote:

> Thanks Benny,
>
> i've tried that too, but it does not work.
> The context is null.
>
> Here's how i do it:
>
> @Inject
> private org.apache.tapestry5.services.Context context;
>
> Should that work?
>
> Stefan
>
>
>
> Am 30.10.2009 um 23:50 schrieb Benny Law:
>
>
>  Hi Stefan,
>>
>> Try injecting org.apache.tapestry5.services.Context into your service and
>> use its getInitParameter() method to retrieve your context parameters.
>>
>> Regards,
>>
>> Benny Law
>>
>> On Fri, Oct 30, 2009 at 3:56 PM, Stefan <stefan@...> wrote:
>>
>>  Hi,
>>>
>>> is there a way to get access to the ServletContext inside a service bean?
>>>
>>> I like to configure some parameters within the web.xml which i need in
>>> some
>>> services.
>>> How can i retrieve these parameters?
>>> Injecting "ApplicationGlobals" does not work.
>>>
>>> Where is my mistake?
>>>
>>> Thanks in advance.
>>> Stefan
>>>
>>
>