Detecting Super Dev Mode from GWT Application
I think the title says it all:
Is there some flag that allows my GWT app to check if it is running in Super Dev mode (something like strings GWT.isProdMode()
maybe)?
source to share
There is an open question about the availability of a public access tool such as GWT.isProdMode()
.
At the same time, if you really need to know, there is a named lazy binding property superdevmode
that you can use in your rules <replace-with>
or <generate-with>
.
source to share
As mentioned, there is a property superdevmode
you can use.
Here's a real-world example:
-
Create a class containing a method that says we're not in SuperDevMode:
public class SuperDevModeIndicator { public boolean isSuperDevMode() { return false; } }
-
Extend the previous class and override the method to say we 're in SuperDevMode:
public class SuperDevModeIndicatorTrue extends SuperDevModeIndicator { @Override public boolean isSuperDevMode() { return true; } }
-
Use only one appropriate class depending on the property
superdevmode
- use lazy binding - put this in your*.gwt.xml
:<!-- deferred binding for Super Dev Mode indicator --> <replace-with class="com.adam.project.client.SuperDevModeIndicatorTrue"> <when-type-is class="com.adam.project.client.SuperDevModeIndicator"/> <when-property-is name="superdevmode" value="on" /> </replace-with>
-
SuperDevModeIndicator
classSuperDevModeIndicator
using lazy binding:SuperDevModeIndicator superDevModeIndicator = GWT.create(SuperDevModeIndicator.class);
-
Use it to check if you are in SuperDevMode or not:
superDevModeIndicator.isSuperDevMode();
Voila!
You will find documentation on deferred binding here .
source to share
You can use the GWTHelper.isSuperDevMode () method implemented below.
public final class GWTHelper {
public static boolean isSuperDevMode() {
final Storage storage = Storage.getSessionStorageIfSupported();
if (storage == null) {
return false;
}
final String devModeKey = "__gwtDevModeHook:" + GWT.getModuleName();
return storage.getItem(devModeKey) != null;
}
}
source to share
To check if there is a dev app server: GWT.getHostPageBaseURL () returns http://127.0.0.1:8888/
Server side: request.getRemoteHost () should return the same (although I haven't tested this).
To check Super Dev mode (vs dev app server without SDM): If GWT.getModuleBaseURL () and GWT.getModuleBaseForStaticFiles () are different, you are in Super Dev mode.
property name = "superdevmode" solution didn't work for me.
source to share