I’ve got one class which is used in both server and client side.
How can I do checking in its constructor that it has been called either from client or server class?
I’ve done it in dirty way – just try if GWT.create() method throws an exception an if it does, run server side code. But how can I avoid this?
public PrintManager() {
try {
factory = GWT.create(MapConfigFactory.class); //clientsiede factory creation
} catch (Exception ex) {
factory = AutoBeanFactorySource.create(MapConfigFactory.class); //serverside factory creator
}
}
com.google.gwt.core.client.GWT.isScript()returnstruewhen the code is running as JavaScript on the client.com.google.gwt.core.client.GWT.isClient()returnsfalsewhen the code is running on the server JVM (shared code).