appbootup
appbootup

Reputation: 9537

How to achieve Two Way data binding in native GWT?

We have been using GWT for around 4 years now. One of the most often discussed features missing in native GWT is data binding. Reading across AngularJs another Google offering, i came across http://devgirl.org/2013/03/21/fun-with-angularjs/ . I do not wish to use GXT or any other third party tools. I also wish to avoid generator related solution.

  1. Is there any way this will ever be implementable in pure native GWT?

  2. Is there any specific reason why GWT cannot provide this out of the BOX?

Upvotes: 4

Views: 3070

Answers (3)

Arnaud Tournier
Arnaud Tournier

Reputation: 1004

I suggest you try HexaBinding, which is non invasive and only focused on data binding. Here is the link : https://github.com/ltearno/hexa.tools/blob/master/hexa.binding/README.md

It works with pure Java, GWT and will soon work also with Android and JavaFX. It may even work with J2Objc but not sure yet...

Upvotes: 1

Christian Achilli
Christian Achilli

Reputation: 5707

I read the post you mention on devgirl about AngularJS. In that post the "2 way data binding" refers to the property of the code to reflect automatically on the view the changes that occurs to the data that the view is currently displaying.

This is achieved in GWT since version 2.1 with the Cell Widgets

In the first paragraph of the Cell Widgets documentation I linked above it is clearly stated that:

A cell widget can accept data from any type of data source. The data model handles asynchronous updates as well as push updates. When you change the data, the view is automatically updated.

If you want to do in GWT something as basic as the example in the devGirl post you need to write a onKeyup handler (in AngularJS you should write a Scope to this purpose) that would copy what you entered to the linked label. Something like this:

...
final TextBox nameField = new TextBox();
final Label enteredName = new Label("");
...
    public void onKeyUp(KeyUpEvent event) {
        enteredName.setText(nameField.getText());
    }
...

Upvotes: 0

Hbf
Hbf

Reputation: 3114

Have you tried GWT Pectin?

I have used it successfully in a larger project some time ago.

Upvotes: 1

Related Questions