Illustration einer tropischen Insel mit Palmen und einem hohen Berg

Java Blog für Programmierer

2 GWT Bibliotheken für REST- und MVP-Anwendungen

· Christian Ullenboom

1.

Die History korrekt zu Implementieren ist das O und A einer GWT-Anwendung. Hier greift unter die Arme, in dem es wie bei REST Pfade einzelne GWT-Seiten mappt. Das Projekt steht am Anfang, die Idee ist aber nett für kleinere GWT-Anwendungen.

Simple Example
@GET@Produces("text/html")public String textHtmlDemo() {        return "welcome home !";}

A new gwt Label with : „welcome home !“ will be appended to the RootPanel.

Example 2
```java
@GET@Path("hello/{name}")public void helloWithIntegerParam(@PathParam("name") Integer myName) {   Window.alert("Hello "+(myName+1));}

If you try to access [http://…/MyPage.html#hello/1](http://.../MyPage.html#hello/1) the helloWithIntegerParam will be invoked **on client side** with the parameter „1“. Since the return type is void, nothing will be added automatically to the Rootpanel. You will just see a popup displaying „Hello 2“.

##### Example 3

```java
```java
@GETpublic Widget demo3() {        return new Button("Click me");}

Yes, returning widgets works too !

##### Example 4

```java
```java
@Path("search/{name}")public class Test {

@PathParam("name")String name;

@GETpublic void search() {   myTextBox.setValue(name);}}

Field initialisation is working the same way.

##### Example 5

```java
```java
@Path("search/{name}")public class Test {

@UiField@PathParam("name")TextBox tbName;

@GETpublic void search() {   // nothing here}}



In this special case, when a field extends „HasValue“ class, the field have to be initialized by yourself, the framework will call „setValue“ with the

2. http://code.google.com/p/mvp4g/

Noch eine Nummer größer als der bescheidene erste REST-Ansatz ist http://code.google.com/p/mvp4g/ aufgestellt. Es implementiert in komplettes MVP-Framework mit Event-Bus, DI, Modulen, Code-Spitting und allen Schnick und Schnack. Die Dokumentation ist mit UML-Diagrammen schon fast unwirklich. Die Einarbeitung dauert, zahlt sich jedoch aus. Eine Umstellung existierender GWT-Anwendungen ist jedoch aufwändig, da mvp4g größere Änderungen nach sich zieht.

Kategorien: GWT, Open Source, Web Frameworks

← Alle Beiträge