Summary of GWT Reading
GWT
let us write client program as Java program. Client is written in Java which is
almost like a traditional GUI application such as having layout managers,
attaching event handlers, and so on. In GWT, GUI code is translated into HTML
and JavaScript. So, instead of compiling Java UI code to Java bytecodes, it
compiles Java to JavaScript source code.
GWT
application consists of a set of modules. A module is a GWT package consisting
of Java code, JavaScript, HTML files, images, data definitions, and whatever
else you need in a web application.
A
typical GWT App has the following directory structure:
- GWT libraries
- a source directory named src
Ø
a module declaration (.gwt.xml)
Ø
a package for the client-side Java
code
Ø
a package for the server-side Java
code.
- a target directory named war. war stands for “web archive”: the deployable package
GWT
Module
- a
fundamental unit of code in GWT
-
consists of a collection of things: Java code; resources like CSS, HTML, or
image files; and GWT customizations, like Java to JavaScript compiler
extensions.
-
Modules can inherit things from other modules. (including css unlike in Java
where it’s basically the code)
- GWT
application starts with an entry point. An entry point is, pretty much,
the GWT GUI equivalent of a main function. In the module file (.gwt.xml), you
declare entry points. The Java class must extend the EntryPoint interface
defined in GWT. The onLoadModule() is the entryPoint method. This is where you
assemble the components in the UI.
Setting Up the UI
- In
setting up, we need interface frame and the Entry Point class.
- The
user interface frame is defined by an HTML file. The HTML file isn’t considered
source code, so it should not be in the src directory. Instead, it should be
placed in the war folder.
- In
the html file, you may define the structure of the UI. For example, creating an
empty box in the UI. The <td> tag creates a box in the HTML layout, but
it’s empty—there’s nothing inside of the tag. In the Java code, we’ll insert something
by referencing it using its id= tag.
- In
onModuleLoad of the entry point class, we can create there the UI widgets like
creating a button and a text box like what we do in AWT or SWING.
- The
main panel of GWT is RootPanel.
Components can be arranged using layout managers for example
VerticalPanel.
RPC in GWT
- An
RPC is something that looks almost like a normal method call, but under the
covers, it’s translated by the system into a request sent from the client to
the server. The return value of the RPC is the response
sent
from the server back to the client.
Two
ways to issue RPC:
1.
Java Native RPC Layer
-
problem with this approach: communication is
slow.
2.
Google-style RPC
-
asynchronous or continuation
passing style for remote calls. The call itself returns nothing. Instead, it takes
an extra parameter, which is a function to invoke on the result of the RPC
whenever it’s received.
Two
parts of RPC in GWT
1.
Client-Side RPC in GWT
Ø Synchronous interface for the service methods.
- In the hello-world
application, it’s called the greeting service. The greeting service interface
is written in the client package because it is the client who is going to be
the user of the interface.
- can be
annotated with information about how they’ll fit into the URL structure
of the
application.
- The
service interface declaration must extend he GWT interface
com.google.gwt.user.client.rpc.RemoteService.
- Any parameters
to a service method must extend either java.lang.Serializable or
the GWT specific
variant com.google.gwt.user.client.rpc.IsSerializable.
Ø Asynchronous interface counterpart of the synchronous interface
- It must have methods with exactly the same name as the methods in the
synchronous interface; each method must have return type void; and each
method adds a parameter at the end, which is an AsyncCallback and whose
type parameter is the return type of the synchronous method.
- It’s really only used by the client—the actual plumbing to map between the asynchronous
and synchronous interfaces is generated by
GWT. The only purpose of the asynchronous
interface is to provide the call interface that the client will use.
2.
Server-Side RPC in GWT
Ø Implement the asynchronous
client interface using a class that extends RemoteServiceServlet.
Ø It is here where the data
sent by the client will be processed.
No comments:
Post a Comment