You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nillehammer <ta...@winfonet.eu> on 2011/06/17 00:28:17 UTC

T5: How to use context-param or init-param from web.xml in contributeApplicationDefaults?

Hi List,

I would like to replace the constant Strings in the method 
"contributeApplicationDefaults" in my AppModule. E.g. replace the 
following line:

configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,de"); // don't 
like the "en,de" here. Would like to replace it.

with something configurable in  a text file. I thought providing the 
values in web.xml either as context-param or as init-param for the 
TapestryFilter was a good idea.

My first try was to inject the Context service as additional parameter 
to the contribution method to get access to the context-params. That did 
not work. The parameter is null and Tapestry throws an exception. Same 
with ApplicationGlobals.

I then browsed through Tapestry's source code and found out that I could 
implement my own filter inheriting from 
org.apache.tapestry5.TapestryFilter. So my next try was to do that and 
override the method "protected void init(Registry registry )". My hope 
was to be able to do something sensible with the 
javax.servlet.FilterConfig that is returned by getFilter(). But I have 
no clue, what to do.

Does someone have an idea what to do?

Thanks in advance,
nillehammer

-- 
http://www.winfonet.eu


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


Re: T5: How to use context-param or init-param from web.xml in contributeApplicationDefaults?

Posted by Nillehammer <ta...@winfonet.eu>.
Hi Martin,

sorry for late reply. I was busy the last two days. I have tried the 
solution you suggested and indeed it just works. That was realy easy! 
Not having found the solution myself after digging into the sources, I 
have to admit that I'm feeling a bit stupid now.

Thanks a lot, for your solution (and for making me feel stupid),
nillehammer

Am 17.06.2011 01:41, schrieb Martin Strand:
> ApplicationDefaults is only one of many SymbolProviders, you don't 
> need to configure that specific SymbolProvider to set the supported 
> locales.
> There are other options, including support for .properties files or 
> system properties.
>
>
> I prefer context parameters myself, everything should "just work" if 
> you add it to web.xml like so:
>
> <context-param>
> <param-name>tapestry.supported-locales</param-name>
> <param-value>en,de</param-value>
> </context-param>
>
> The ServletContextSymbolProvider will handle the rest for you.
> I'm sure you're already doing this for other symbols, at least 
> "tapestry.app-package" :)
>
>
> On Fri, 17 Jun 2011 00:28:17 +0200, Nillehammer 
> <ta...@winfonet.eu> wrote:
>
>> Hi List,
>>
>> I would like to replace the constant Strings in the method 
>> "contributeApplicationDefaults" in my AppModule. E.g. replace the 
>> following line:
>>
>> configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,de"); // 
>> don't like the "en,de" here. Would like to replace it.
>>
>> with something configurable in  a text file. I thought providing the 
>> values in web.xml either as context-param or as init-param for the 
>> TapestryFilter was a good idea.
>>
>> My first try was to inject the Context service as additional 
>> parameter to the contribution method to get access to the 
>> context-params. That did not work. The parameter is null and Tapestry 
>> throws an exception. Same with ApplicationGlobals.
>>
>> I then browsed through Tapestry's source code and found out that I 
>> could implement my own filter inheriting from 
>> org.apache.tapestry5.TapestryFilter. So my next try was to do that 
>> and override the method "protected void init(Registry registry )". My 
>> hope was to be able to do something sensible with the 
>> javax.servlet.FilterConfig that is returned by getFilter(). But I 
>> have no clue, what to do.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
http://www.winfonet.eu


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


Re: T5: How to use context-param or init-param from web.xml in contributeApplicationDefaults?

Posted by Martin Strand <do...@gmail.com>.
ApplicationDefaults is only one of many SymbolProviders, you don't need to  
configure that specific SymbolProvider to set the supported locales.
There are other options, including support for .properties files or system  
properties.


I prefer context parameters myself, everything should "just work" if you  
add it to web.xml like so:

<context-param>
   <param-name>tapestry.supported-locales</param-name>
   <param-value>en,de</param-value>
</context-param>

The ServletContextSymbolProvider will handle the rest for you.
I'm sure you're already doing this for other symbols, at least  
"tapestry.app-package" :)


On Fri, 17 Jun 2011 00:28:17 +0200, Nillehammer  
<ta...@winfonet.eu> wrote:

> Hi List,
>
> I would like to replace the constant Strings in the method  
> "contributeApplicationDefaults" in my AppModule. E.g. replace the  
> following line:
>
> configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,de"); // don't  
> like the "en,de" here. Would like to replace it.
>
> with something configurable in  a text file. I thought providing the  
> values in web.xml either as context-param or as init-param for the  
> TapestryFilter was a good idea.
>
> My first try was to inject the Context service as additional parameter  
> to the contribution method to get access to the context-params. That did  
> not work. The parameter is null and Tapestry throws an exception. Same  
> with ApplicationGlobals.
>
> I then browsed through Tapestry's source code and found out that I could  
> implement my own filter inheriting from  
> org.apache.tapestry5.TapestryFilter. So my next try was to do that and  
> override the method "protected void init(Registry registry )". My hope  
> was to be able to do something sensible with the  
> javax.servlet.FilterConfig that is returned by getFilter(). But I have  
> no clue, what to do.

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


Re: T5: How to use context-param or init-param from web.xml in contributeApplicationDefaults?

Posted by Nillehammer <ta...@winfonet.eu>.
Yeah, a possible way to go. But I'd like a more "persistent" solution 
hence the idea of using params in web.xml

Am 17.06.2011 00:36, schrieb Lenny Primak:
> I use system properties.
>
>
>
> On Jun 16, 2011, at 6:28 PM, Nillehammer<ta...@winfonet.eu>  wrote:
>
>> Hi List,
>>
>> I would like to replace the constant Strings in the method "contributeApplicationDefaults" in my AppModule. E.g. replace the following line:
>>
>> configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,de"); // don't like the "en,de" here. Would like to replace it.
>>
>> with something configurable in  a text file. I thought providing the values in web.xml either as context-param or as init-param for the TapestryFilter was a good idea.
>>
>> My first try was to inject the Context service as additional parameter to the contribution method to get access to the context-params. That did not work. The parameter is null and Tapestry throws an exception. Same with ApplicationGlobals.
>>
>> I then browsed through Tapestry's source code and found out that I could implement my own filter inheriting from org.apache.tapestry5.TapestryFilter. So my next try was to do that and override the method "protected void init(Registry registry )". My hope was to be able to do something sensible with the javax.servlet.FilterConfig that is returned by getFilter(). But I have no clue, what to do.
>>
>> Does someone have an idea what to do?
>>
>> Thanks in advance,
>> nillehammer
>>
>> -- 
>> http://www.winfonet.eu
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


-- 
http://www.winfonet.eu


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


Re: T5: How to use context-param or init-param from web.xml in contributeApplicationDefaults?

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I use system properties. 



On Jun 16, 2011, at 6:28 PM, Nillehammer <ta...@winfonet.eu> wrote:

> Hi List,
> 
> I would like to replace the constant Strings in the method "contributeApplicationDefaults" in my AppModule. E.g. replace the following line:
> 
> configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,de"); // don't like the "en,de" here. Would like to replace it.
> 
> with something configurable in  a text file. I thought providing the values in web.xml either as context-param or as init-param for the TapestryFilter was a good idea.
> 
> My first try was to inject the Context service as additional parameter to the contribution method to get access to the context-params. That did not work. The parameter is null and Tapestry throws an exception. Same with ApplicationGlobals.
> 
> I then browsed through Tapestry's source code and found out that I could implement my own filter inheriting from org.apache.tapestry5.TapestryFilter. So my next try was to do that and override the method "protected void init(Registry registry )". My hope was to be able to do something sensible with the javax.servlet.FilterConfig that is returned by getFilter(). But I have no clue, what to do.
> 
> Does someone have an idea what to do?
> 
> Thanks in advance,
> nillehammer
> 
> -- 
> http://www.winfonet.eu
> 
> 
> ---------------------------------------------------------------------
> 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