You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel Jue <te...@gmail.com> on 2009/01/29 07:28:13 UTC

Re: How Can I not hardcode value in contributeApplicationDefaults method.

In the case of Tomcat, you can also store these in a Context.xml file,
which can be configured differently for each server (including your
development machine).  The context.xml file can be unique to each
Tomcat instance, and live in Tomcat/conf/context.xml or
Tomcat/conf/Catalina/localhost/context.xml.default

See the docs here:
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

Then you can do things like this in the xml file:

<Context>
	<Environment name="useHTTP" type="java.lang.String" value="true" />
	<Environment name="PRODUCTION_MODE" type="java.lang.String" value="false" />
	<Environment name="HELP_DESK_EMAIL" type="java.lang.String"
value="MIB@sekritsqrl.gov" />
</Context>

I read these values in a Module, and set the corresponding values in
the place Tapestry reads it.  For instance, when I read the useHTTP
value it might also force the user to use SSO coming into the app,
besides just changing the metadata locator for the entire app.

You can also put your JNDI resources in this context file, just beware
that you may need to jump through a hoop if you can't have plain text
passwords--Tomcat Realms don't work here.
You at least need the JNDI references in your web.xml, but the actual
configuration can go in the context file.

Daniel
On Thu, Jan 29, 2009 at 12:56 AM, Geoff Callender
<ge...@gmail.com> wrote:
> Whether you use AppModule.java, app.properties, or web.xml, it's still
> hard-coding. Only constants belong in there.
>
> Environment-specific properties can be set as system properties before
> starting the server,
> eg. for JBoss on Unix: setenv JAVA_OPTS '-Dtapestry.production-mode=false
> -Dtapestry.compress-whitespace=false'
> eg. for Tomcat in Windows: set JAVA_OPTS=-Dtapestry.production-mode=false
> -Dtapestry.compress-whitespace=false
>
> Or you can pick them up in the app from a file in the classpath, eg. in the
> JBoss server's conf/ directory or Tomcat's server/lib/ (is that right for
> Tomcat?); with this solution:
> http://wiki.apache.org/tapestry/Tapestry5HowToReadSymbolsFromPropertiesFile
>
> Geoff
>
> On 29/01/2009, at 1:06 PM, bongosdude wrote:
>
>>
>> How are about other values like production_mode, cookie age which have
>> different values in DEV, QA and Production environments?
>>
>> Even put it in the web.xml is not good either? I cannot change web.xml
>> when
>> we release software to QA and production.
>>
>> Thanks
>> -B
>>
>>
>> Harald Geritzer-2 wrote:
>>>
>>>
>>> you can put them into your web.xml file:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!DOCTYPE web-app
>>>        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>>>        "http://java.sun.com/dtd/web-app_2_3.dtd">
>>> <web-app>
>>>    <display-name>MyApp</display-name>
>>>    <context-param>
>>>        <param-name>tapestry.supported-locales</param-name>
>>>        <param-value>de</param-value>
>>>    </context-param>
>>> ..
>>> </web-app>
>>>
>>> bongosdude schrieb:
>>>>
>>>> hardcoded value in AppModule.contributeApplicationDefaults method is not
>>>> a
>>>> best practice.
>>>>
>>>> class AppModule {
>>>> ......
>>>>   public static void contributeApplicationDefaults(
>>>>       MappedConfiguration<String, String> configuration ) {
>>>>
>>>>       configuration.add( SymbolConstants.SUPPORTED_LOCALES, "de,en" );
>>>>       configuration.add( "tapestry.default-cookie-max-age", "31536000"
>>>> );
>>>>       configuration.add( SymbolConstants.PRODUCTION_MODE, "false" );
>>>>   }
>>>>
>>>> }
>>>>
>>>> I would like to put those values: PRODUCTION_MODE, cookie-max-age and
>>>> SUPPORTED_LOCALES in a properties file (i.e. app.properties) and then
>>>> get
>>>> the values from that file. So in QA, dev, the value of PRODUCTION_MODE
>>>> should be false, but in production the value should be true.
>>>>
>>>> How can I inject appropriate value from app.properties file?
>>>>
>>>> i.e @Inject Message message;
>>>>
>>>> Thank for any suggestion
>>>> -B
>>>>
>>>>
>>>>
>>>> -----
>>>> B Amigo:super:
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>>
>>
>> -----
>> B Amigo:super:
>> --
>> View this message in context:
>> http://www.nabble.com/How-Can-I-not-hardcode-value-in-contributeApplicationDefaults-method.-tp21716553p21719510.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
>>
>
>
> ---------------------------------------------------------------------
> 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