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:
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide
|Graph Any Data with Cacti!||Apr 27, 2017|
|Be Kind, Buffer!||Apr 26, 2017|
|Preparing Data for Machine Learning||Apr 25, 2017|
|openHAB||Apr 24, 2017|
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
- Graph Any Data with Cacti!
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- The Weather Outside Is Frightful (Or Is It?)
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Server Technology's HDOT Alt-Phase Switched POPS PDU
- IGEL Universal Desktop Converter
- From vs. to + for Microsoft and Linux