Web 2.0 Development with the Google Web Toolkit
Using GWT requires learning about several packages. The most important ones are:
com.google.gwt.http.client: provides the client-side classes for making HTTP requests and processing the received responses. You will use it if you need to do some AJAX on your own, beyond the calls done by GWT itself.
com.google.gwt.i18n.client: provides internationalization support. You will need it if you are developing a system that will be available in several languages.
com.google.gwt.json.client and com.google.gwt.xml.client: used for parsing and reading XML and JSON data.
com.google.gwt.junit.client: used for building automated JUnit tests.
com.google.gwt.user.client.ui: provides panels, buttons, text boxes and all the other user-interface elements and classes. You certainly will use these.
com.google.gwt.user.client.rpc and com.google.gwt.user.server.rpc: these have to do with remote procedure calls (RPCs). GWT allows you to call server code transparently, as if the client were residing in the same machine as the server.
You can find information on these and other packages on-line, at google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.html.
Now, let's turn to a practical example. Creating a new project is done with the command line rather than from inside Eclipse. Create a directory for your project, and cd to it. Then create a project in it, with:
/path/to/GWT/projectCreator -eclipse ProjectName
Next, create a basic empty application, with:
/path/to/GWT/applicationCreator -eclipse ProjectName \ com.CompanyName.client.ApplicationName
Then, open Eclipse, go to File→Import→General, choose Existing Projects into Workspace, and select the directory in which you created your project. Do not check the Copy Projects into Workspace box so that the project will be left at the directory you created.
After doing this, you will be able to edit both the HTML and Java code, add new classes and test your program in hosted mode, as described earlier. When you are satisfied with the final product, you can compile it (an appropriate script was generated when you created the original project) and deploy it to your Web server.
Let's do an example mashup. We're going to have a text field, the user will type something there, and we will query a server (okay, with only one server, it's not much of a mashup, but the concept can be extended easily) and show the returned data. Of course, for a real-world application, we wouldn't display the raw data, but rather do further processing on it. The example project itself will be called exampleproject, and its entry point will be example, see Listing 1 and Figure 1.
Listing 1. Projects must be created by hand, outside Eclipse, and imported into it later.
# cd # md examplefiles # cd examplefiles # ~/bin/gwt/projectCreator -eclipse exampleproject Created directory ~/examplefiles/src Created directory ~/examplefiles/test Created file ~/examplefiles/.project Created file ~/examplefiles/.classpath # ~/bin/gwt/applicationCreator -eclipse exampleproject \ com.kereki.client.example Created directory ~/examplefiles/src/com/kereki Created directory ~/examplefiles/src/com/kereki/client Created directory ~/examplefiles/src/com/kereki/public Created file ~/examplefiles/src/com/kereki/example.gwt.xml Created file ~/examplefiles/src/com/kereki/public/example.html Created file ~/examplefiles/src/com/kereki/client/example.java Created file ~/examplefiles/example.launch Created file ~/examplefiles/example-shell Created file ~/examplefiles/example-compile
According to the Getting Started instructions on the Google Web Toolkit site, you should click the Run button to start running your project in hosted mode, but I find it more practical to run it in debugging mode. Go to Run→Debug, and launch your application. Two windows will appear: the development shell and the wrapper HTML window, a special version of the Mozilla browser. If you do any code changes, you won't have to close them and relaunch the application. Simply click Refresh, and you will be running the newer version of your code.
Now, let's get to our changes. Because we're using JSON and HTTP, we need to add a pair of lines:
Free DevOps eBooks, Videos, and more!
Regardless of where you are in your DevOps process, Linux Journal can help!
We offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, and advice & help from the expert sources like:
- Linux Journal
Web Development News
|PostgreSQL, the NoSQL Database||Jan 29, 2015|
|HPC Cluster Grant Accepting Applications!||Jan 28, 2015|
|Sharing Admin Privileges for Many Hosts Securely||Jan 28, 2015|
|Red Hat Enterprise Linux 7.1 beta available on IBM Power Platform||Jan 23, 2015|
|Designing with Linux||Jan 22, 2015|
|Wondershaper—QOS in a Pinch||Jan 21, 2015|
- PostgreSQL, the NoSQL Database
- Sharing Admin Privileges for Many Hosts Securely
- HPC Cluster Grant Accepting Applications!
- Designing with Linux
- Wondershaper—QOS in a Pinch
- January 2015 Issue of Linux Journal: Security
- Internet of Things Blows Away CES, and it May Be Hunting for YOU Next
- Ideal Backups with zbackup
- Red Hat Enterprise Linux 7.1 beta available on IBM Power Platform
- Slow System? iotop Is Your Friend