First steps with GWT - 003

In most of the WEB (in our case GWT) applications we need to access the server to get the information from databases. So, in GWT we are using the standard GWT-RPC which resolves the automatic serialization of the parameters and results from/to server.

Problem: During any application we may need multiple parts of information from server that can be implemented by different RPCs. Question is how to achieve this: by having multiple RPC calls to the server, where the data is small and retrieved quickly (the first impression), or to make a new super-RPC that will retrieve all data and does one single call to the server ?

Preambul: the serialization of the data thru RPC is quite fast, if we activate the compression in the RPC-servlet we can make it even faster.

Solution: after lots of tests we can recommend that the "second" solution is better (one call to transfer more data at once).

Problem: "SELECT *" or "SELECT col1, col2" ?

This recommendation is not related with GWT, but with the database access in general. It's faster to write the SELECT statements more precisely, which means instead of writing the generic SELECTs like this

SELECT * FROM table

where we are using only a subset of column, it's better to write this one:

SELECT col1, col2 FROM table

because the only col1,col2 will be retrieved from the database, not the rest of unused columns and in case of big tables, with many columns, this is a major improvement.

First steps with GWT - 002

Multi-lines Label

GWT has the widget Label to display the text on one single line (ignoring the end-of-line characters).

Problem:
We want to display multi-lines text in a "fatter" label (big size, let's say 500x400 pixels).

Solution:
The classic end of lines in Java or HTML doesn't work "\n", "\r\n" or <br> . So, what can we do?

We can use the bellow magic lines of code:

Label textLabel = new Label ("bla bla \n bla bla", false);
DOM.setStyleAttribute(textLabel.getElement(), "whiteSpace", "pre");

Adding this label to a scroll panel will assure that the scroll functionality is available too, for too many lines of text :-)

Simple calculator in Java Swing

Here you can have some samples http://bytes.com/forum/thread472012.html.

If you want more info then tell me and I'll send you the complete source code for it.

Ciao.

To REST, or not to REST

What is REST?

A simple definition is:

REST is a way of thinking, not a protocol or standard; it's a style of designing loosely coupled Web applications that rely on named resources - in the form of URLs (Uniform Resource Locators), URIs (Uniform Resource Identifiers), and URNs (Uniform Resource Names), for instance - rather than messages.



REST supports CRUD (create, read, update, delete) type of actions through HTTP requests: POST, GET, PUT and DELETE, respectively.

Java REST framework: Restlet

Restlet is a lightweight java framework that implements REST and can be found at
www.restlet.org.

Restlet applications are similar to servlet applications because they reside in the container, but they are different because:
- restlets don't have anything to do with HTTP and its stateful artifacts (ie. cookies, session, etc.)
- restlet framework is extremely lightweight.

It's based on few classes: abstract Application, Resource, Router, Variant.

Resource types in the Restlet framework are known as Restlets.

Read more about Restlet:
http://www.restlet.org/documentation/1.0/tutorial

An expample of an REST API can be found here:
http://developer.yahoo.com/traffic/rest/V1/

First steps with GWT - 001

The Google Widget Toolkit (GWT) is the simple and consistent way to build the WEB client applications by using the Java language. The "toolkit" is actually a "compiler" of the Java code into Javascript, which is executed on client's machine. Because of that, it means that not every Java class is supported by GWT. Its latest version (GWT 1.5 RC1) supports the JDK 5.x, including generics and smart for loops.

The official web site is located here: http://code.google.com/webtoolkit/

Widgets

The widgets are UI controls that will be used in our "java pages" (has nothing to do with JSP J). They are very similar (panels, layouts, event listeners etc.) with the "Swing cousins", but so different (some widgets UI don't keep reference to the model or children, so further actions like edit or delete are not possible) from them. The whole list of them can be found at the following link: http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.UserInterface.html as well as the developer's guide: http://code.google.com/webtoolkit/documentation/

Extensions

There are different types (free or not) of other libraries that, based on GWT, have created more widgets, and look and feels. Here we present two of them: GWT-Ext and GWT-Ext-UX.

1. GWT-Ext

This is a free library that is built on top of GWT and EXT (don't make confusion with Ext GWT that is built by company ExtJS and is not free). The GWT-Ext has nicer controls and functionality, and it can be found at this link: http://gwt-ext.com/

2. GWT-Ext UX

This is a smaller free library that is an user's extension, similar like the previous one (GWT-Ext). It can be found at link: http://www.gwt-ext.com/demo-ux/

Both extensions have demo web sites, where the whole collection of widgets can be found, including their sources.


Development environment

The development can be done with various IDs (Eclipse, JIdea, etc), but here we are talking about Eclipse, because everybody knows, that it's free and very powerful.

So we have here the small list of some prerequisites:


The GWT Designer plug-in is from the company Instantiations and, unfortunately, it's not free but it seems to be the best; at least you can use the evaluation version.


First project with Eclipse


A project has a specific directory structure and files. A GWT project contains at least one "module". The main file is with extension ".gwt.html", and it's the descriptor of the application. It includes other modules that are inherited, the entry point, new modules we are defining, servlets mapping, different application init properties, etc.


We can create a new project using the Eclipse new project wizard (using extensively the next button).


After we hit the button "Finish" the project is generated and it has the following content (see the below image). It contains 3 main packages: "client", "server" and "public".



Under client we have the code that will be "compiled" in Javascript and will run on client's machine (see here that there are Java class restrictions).


Under server we have the code that will run, obviously, on the server machine, and it can use any Java class (Java à Javascript conversion doesn't happen here).


Under public we have the other web resources, which can be used with the GWT, like: html pages, css files, images etc.


From now on, we can add more code to the packages: client, server or public, based on what we want to achieve :-) Success :-)