21⟩ What is GWT Compiler?
GWT Compiler used to convert the client side Java code to Javascript at the time of building the source files.
“EXT GWT frequently Asked Questions in various EXT Google Web Toolkit job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”
GWT Compiler used to convert the client side Java code to Javascript at the time of building the source files.
Yes GWT works in all the browsers because GWT compiler creates javascript code per browser and per localization.
I meant, if you configure module.xml with Firefox and IE then GWT compiler will create javascript code for both browsers seperately.
And when you load the application it first check from which browser you are opening the application and it will load the corresponding javascript.
It means GWT supports Cross browser functionality.
Problems with indexing by search engines - IMHO, this should be the biggest disadvantage of using GWT, or pure JS web applications in general. Since the content, layout, everything is created "on-the-fly" with JS, the search engine will only see a very short HTML page and that's that - you have to take care of this somehow yourself (for example, using cloaking). Google has finally started to work on a solution for this, however it doesn't seem to attractive to me.
Update: Google has finally addressed this problem. However, I'll leave this as a trade-off because making the application crawable still requires more effort than in other frameworks. At least now we have a "standard" to follow and don't have to use some dubious techniques (like cloaking).
Need lot of memory to run it in dev mode.
High compile time.
Every server call will be ajax.
You will loose control on your javascript.
To reduce the compilation time, choose favorite browser and add the user.agent property in the module configuration file.
Values: ie6,ie8,gecko1_8,safari,opera
module.gwt.xml:
<module..>
<inherits...>
<set property name="user.agent" value="ie8,opera">
</module..>
To simply put ‘Write JavaScript using JAVA’
And in a little more detail:
Compiles JAVA code into JavaScript code
Takes care of cross browser compatibility by generating a browser specific code
Not client side alone. Has a deployable server side components (which is not compiled into JavaScript)
Client communicates to server via GWT-RPC call (if services are written using GWT),
Supports http calls using JSON and XML format
Supports AJAX calls
With JSNI (Javascript native interface) can mix javascript code with java code
java can call javascript method
javascript can call java method
A user-defined class is serializable if all of the following apply:
It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
All non-final, non-transient instance fields are themselves serializable, and
As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.
One key difference though is that , for security reasons, all Serializable classes must be included in a serialization policy, which is generated at compile time, while IsSerializable classes do not have that requirement.
If your interest is purely in GWT, and you don't e.g. share your model classes between the web application and another application, I suggest you have your model classes/DTOs implement IsSerializable.
Google Web Toolkit includes a library that emulates a subset of the Java run-time library. The list below shows the set of JRE packages, types and methods that GWT can translate automatically. Note that in some cases, only a subset of methods is supported for a given type.
java.lang
java.lang.annotation
java.math
java.io
java.sql
java.util
java.util.logging
For this purpose only GWT has one Asynchronous interface which has one parameter called AsyncCallBack, using this callback object it will call the client side code once the server completed the execution.
So basically all the calls to server side method will have two call back methods
onSuccess()
onFailure()
If the server side method executed properly then onSuccess() method will be called otherwise onFailure() method will be called, so based on this we can proceed with our functionality.
In GWT we can handle page navigation using couple of ways.
1. Using History tokens
2. Clearing the content panel and load the new page in the content panel.
Generators allow the GWT coder to generate Java code at compile time and have it then be compiled along with the rest of the project into JavaScript.
Run ant build in the root folder of the application
•By default gwt compiler creates optimized JS files for some browsers.
–Disadvantage is it takes a lot of time to compile each change because of the permutations
Steps:
1) Open command prompt
2) Go to the application root folder
3) Run command as "ant build"
Then you can see compile logs are coming. If you see BUILD SUCCESSFUL it means no error in your application. If BUILD FAILED it means there is an error in your application.
To use RequestBuilder we need to inherit HTTP Module in module.xml file
<inherits name="com.google.gwt.http.HTTP"/>