First, the introduction
If you are a Java software and Ajax developer, then Google Web Toolkit (GWT) should have caught your eye.
Google has released this free development kit under the Apache License agreement in May 2006. GWT was designed to simplify the development of AJAX applications in the Java language. The beta version of Google's initial release can be applied to Windows and Linux platforms and promises to release a version of Mac OS X later.
This article explores the complete process of using GWT and familiar Java tools on Mac OS X, such as the Apache Ant,tomcat 5.0 servlet container and the IntelliJ idea integrated development environment to develop a simple AJAX application.
Note This article assumes that the reader has a certain base of Java and Ant usage.
Second, use Ant with GWT
I downloaded the GWT Linux beta version and chose the Java Development application, then compiled with an ant build file, and finally published the application on a Tomcat 5.0 instance. Note that this ant file is running the GWT java-to-javascript compiler. In fact, this "compiler" is just a command-line script that executes a GWT Java class that is responsible for writing JavaScript for the application.
Using GWT Beta includes two development methods: Host mode and Web mode.
The host approach is to use an embedded GWT browser and intermediate development steps; In this way, your compiled code continues to run in a Java Virtual machine (JVM). However, the host approach cannot be applied to our Mac OS X users who use the Linux version of the operating system. Only if Google releases a version of Mac OS X can we use the host method.
Three, different styles of web development
While creating a remote procedure call (RPC) service, this article discusses in detail some of the web development-related tasks that typical GWT developers might face. RPC is part of a software model designed primarily for applications that use service-oriented architecture (SOA). These development tasks include:
· Automate the development and release steps with a build file (build and run the GWT compiler, then publish the compiler's output, and publish your server-side Java class files to a servlet container, such as tomcat,jetty or resin).
· Use Firefox's DOM inspector to observe the HTML generated by the GWT application.
· Reset the parts on the page without having to access the inner HTML (since you're using GWT's Java API).
· Make sure that HTML is a valid tag, for example, your organization may need to be based on a particular XHTML document type.
Four, the service function
First, I'll briefly describe the service that this sample application is creating, and design This example to show the model that GWT uses.
The application displays a form in the browser that asks the user to enter their name, age, and country of origin. When the user submits the form by clicking the button, the application displays a server response in a text field without initializing a page refresh. Figure 1 shows what the application looks like in the Safari browser.
Figure 1. A simple view generated by GWT
For example, when a user keeps a text box blank and clicks the Ok,submit button, the result shown in Figure 2 is displayed.
Figure 2: The application displays an error message in red