tags:

views:

59

answers:

1

I would like to have my GWT application use different constants when debugging or developing vs when deployed. What is the right way to do this? My web searches turn up a lot of pages about debugging GWT applications, which isn't what I'm looking for.

+1  A: 

This looks like a job for deferred binding! ;)
It would look something like this (put this in your module XML file, I haven't actually tested it, but you should get the gist of it):

  <define-property name="debug" values="true,false" />
  <set-property name="debug" value="true" />

  <replace-with class="package.Constants">
    <when-type-is class="package.Constants"/>
  </replace-with>

  <replace-with class="package.ConstantsDebug">
    <when-type-is class="package.Constants" />
    <when-property-is name="debug" value="true"/>
  </replace-with>

See the docs for more information on available parameters, rules and whatnot.

Igor Klimer
Exactly what I wanted. Thanks.
Michael Donohue
Just to add, GWT already has a debug flag - `gwt.enableDebugId` that controls the `ensureDebugId()` method. You can use that as a reference implementation, or better - can reuse the same flag.
sri