Thursday, March 24, 2016

GWT React

We currently have a large GWT application that we have been working on for the last 4 years. We use Uibinder and Widgets very

 heavily, although we have our own Widget set and RPC mechanism. The application is being constantly expanded and realistically 

won't be fully rewritten for 8-10 years. Given the news about J2CL not supporting widgets, I have been thinking about how we could 

migrate to a world without widgets on an incremental basis. 


In parallel, I have also being exploring writing native mobile apps. We tried the mobile web but it wasn't great and we really needed

hardware integration for NFC and total offline capabilities. Which brings us React. I found React Native and started researching 

and playing around. I have to say I am very impressed. In my mind it is a game changer. They are getting close to allowing one code 

base to support iOS, Android and the Web with only about 10-20% custom code for each platform.


The more I played with React Native, the more I liked the React declarative model for defining UI's. I started thinking that React 

would be ideal for incrementally embedding within an existing GWT application. Facebook designed it so they could incrementally

role it out into their existing Web application. When GWT 2.8 beta came out, I wanted something to try the new JsInterop out on.

React seemed like a good candidate. After a couple of weeks of experimenting, I have a working proof of concept for React. I 

have to say it was a real challenge and really pushed the capabilities of JsInterop. I had to do some javascript hacking to get it 

to work. My goal was to create an interface that was as close to JavaScript as possible. That way you could use the many React

tutorials and apply them to writing GWT React code without some huge mental translation.


I decided to try and port to Java. The reason for this was so I could have a direct comparison 

between the Java and Javascript code. I have implemented enough of the React API to get this working. In addition, I also integrated 

a 3rd party React component called React Router ( This is pretty much the de facto standard 

for routing in the React world. This proved that I could consume React components written by other people. Overall I am pleased with 

how it turned out. I find the java version easier to follow, especially since the Prop types are explicit. It would be nice to support JSX

 instead of the legacy createElement interface. However, it isn't terrible. The Java version was 465 lines in total vs 419 for the original 

JavaScript code. If you take out the import statements which I don't really count because the IDE creates them for you, the Java version 

was actually only 414 lines. You can take a look at the code here :


At this point I am about 80% sure what I have created could become a viable production solution. The next steps I want to do are:

  1. Finish the API
  2. Test embedding Gwt React within an existing GWT Widget based application.
  3. Build an API for Redux ( and React Redux ( which is becoming the de facto standard for the MC in MVC. I will probably re-implement todomvc using this. 


If I don't hit any roadblocks, I will either publish to Github or make the source publicly available. I haven't made my mind up on which approach I will take.

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment