📜 ⬆️ ⬇️

Ajax + Google = GWT

Life Story. (Preface)

A year ago, I had to start developing a UI for a javascript web service. Over time, the UI has grown into a full-fledged thin client with a fairly dynamic interface and rather big business logic. How did this javascript start to annoy me?

Basically, there were 3 problems.
1) lack of inheritance and encapsulation. This seriously affected business logic. Of course, there are Prototype and many other different frameworks to solve this problem, but after Java it all seemed far-fetched.
2) the inability to create complex UI elements. It would be desirable to take out repeating pieces UI in separate and use them, simply redefining some functionality.
3) multi-browser. Even if you write everything under firefox - it does not always work in IE. Particularly pleased with the differences in XML parsing and default values ​​of padding and marging styles.

In my opinion, the first two problems were caused by the lack of OOP. Clear and intuitive. The solution was simple and in the forehead: write a Java translator in JavaScript (JS). From the point of view of Java syntax, JS is much stricter, and therefore translation seemed quite solvable. After additional research I was surprised and pleased by the fact that Google just took and solved all my problems ...

Google Web Toolkit (GWT).

Everything is very simple - we are writing an application in Java using standard sets of utilities and Java 1.4 classes, ready-made controls for UI and a set of base classes from Google. There are limitations there, but not too strong. Very close to a regular GUI application.
Then all this is compiled by the GWT compiler and at the output we get an html file with js-code. We get 6 different options: default, opera, safari, gecko, gecko1.8, ie6. Nothing extra. For each browser, only its own version of the code is loaded.
')
From the point of view of a Java developer (and not only) GWT supports such useful things.
1) Java compiler in javascript
2) debag.
3) multi-browser.
4) the possibility of writing modules.
5) a wide range of widgets, panels and controls.
6) RPC
7) JUnit
8) internationalization / Resource banding.
9) JavaScript Native Interface - Inserts on pure javascript. Ability to pull javascript from Java and vice versa.
10) JSON and much more.

Google Mail, Google Maps, Google Base were written on GWT (or its prototypes)

For whom is the GWT.

I think that this framework will be mainly useful to Java developers, who for some reason or other write UI. GWT makes it possible not to abandon high-level languages ​​and their advantages. There is already support for GWT in IntellijIDEA and Ecipse.

Example
 public class HelloCrazyWorld implements EntryPoint
 {
     public void onModuleLoad ()
     {
          Label label = new Label ("Click me");
          label .addClickListener (new ClickListener ()
          {
              public void onClick (Widget sender)
              {
                  Window.alert ("Hello!");
              }
         });

        RootPanel.get (). Add (label); 
     }
 }


Ps. Someone tell me how best to frame the code tags?

Source: https://habr.com/ru/post/9668/


All Articles