Over a million developers have joined DZone.

The Ease of Angular with GWT

DZone 's Guide to

The Ease of Angular with GWT

· Java Zone ·
Free Resource

Let's see a quick example. Our framework builds with the standard GWT MVP, but we eliminated view and presenter interfaces. We are also relying on pure html templates, not gwt ui.xml-s or imperative UI building, but that's your choice.

Now let's say we have HTML template:

<span id="nameLabel"/>
<button id="myButton">Clickme</button>

And in the ViewImpl class:

new LightLabel("#nameLabel")
new LightButton("#myButton")

And the Presenter (that's also the Activity):

private String labelText;
public void buttonClicked() {
    setLabelText("You clicked me!");

Note a few things:

  • The example framework uses html templates, but you're actually free to use your own solution in ViewImpl classes
  • The ViewImpl class is dumb: it merely declares components and their bindings.
  • The bindings are easy to express with the magically generated property and method literals , but it's still typesafe, compile-time checked.
  • In this example the presenter is also the model (it contains the labelText), but that's also your choice, you can put it in a different Model class.
  • The presenter works with the model only. Changes are automatically propagated to the view and vice-versa. There's no need of a view or presenter interface, and you don't have to manually propagate data to the view components and manually fetch them when you need them in the presenter. They're just there.
The magic I mentioned is performed by lombok-ds, our extension of lombok-pg. We are planning to switch to APT though.
Well, the above example is probably the most simple one. The  github page contains more examples and principles to follow. We implemented an entire large-scale project with this approach, and it turned out to be pretty cool.
Please let us know if you're interested.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}