Search code examples
javagwtjsni

How to optionally turn on JSNI part in GWT?


I have some javascript scripts. I also added a button that launches these scripts on main page of my app. In pre-release time I use this button and scripts actively, but I need to remove this button and scripts for release version.

Is there any practices for adding/removing UI elements on pre-release (debug) and release versions of app? Maybe via property in gwt.xml?


Solution

  • You could introduce a configuration property that you can set and query in GWT to detect wether you are building a release or a debug version.

    In your gwt.xml file:

    <define-configuration-property name="yourkey" is-multi-valued="false" />
    <set-configuration-property name="yourkey" value="yourvalue" />
    

    You can then use binding rules to bind different implementations to a class.

    (See deferred binding): https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsDeferred