Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Javaland 2015 - Rich Internet Applications with...

Javaland 2015 - Rich Internet Applications with JBoss Errai

In addition to a complex server architecture web and mobile applications also have a challenging client code base. However traditional Java frameworks focus on server side rendering and do not integrate JavaScript very well. JBoss Errai is a framework which helps developing large, scalable rich web applications using a consistent, standardized programming model for client development. Leveraging the Google Web Toolkit Errai brings a proven server-side programming model to the browser. The framework makes it possible to build rich web applications completely in Java. In a typesafe way with reducing boilerplate code.

Avatar for Johannes Barop

Johannes Barop

March 25, 2015
Tweet

More Decks by Johannes Barop

Other Decks in Programming

Transcript

  1. 4 Browser as application platform §  Increasing demand for rich

    web applications §  Browsers became stable and reliable §  HTML5 provides rich set of components §  Portable (desktop / mobile / …) Rich Client Revolution 07.04.15
  2. 5 Browser as enterprise application platform §  Also suited for

    corporate systems §  Compared to desktop applications: §  Easier administration (installations, updates, scalability) §  Better interoperability Rich Client Revolution 07.04.15
  3. 6 Problem: Browser not a trusted or safe environment § 

    State can be manipulated à Validation etc. needed §  Server (Java) and browser (JavaScript) platform are very different from each other à Code Duplication Rich Client Revolution 07.04.15
  4. 7 Problem: Lack of integration of browsers technologies in Java

    §  Java frameworks focus on server side HTML templating §  Frontend resources only “dumb” static resources §  Need for a dedicated frontend setup (grunt / gulp / …) §  à Polyglot setup §  à “Native web” approach but very weak integration Rich Client Revolution 07.04.15
  5. 8 Polyglot – Problem: Integration 07.04.15 IDE Compiler Text editor

    Build tools InDesign HTML CSS PhotoShop PROBLEM
  6. 11 §  Same language for back- and frontend §  Much

    better integration §  Cleaner project infrastructure §  Less different tools §  Easier development Monoglot Project 07.04.15
  7. 12 NodeJS §  Based on V8 JavaScript engine §  Run

    JavaScript in the server Errai §  Run Java in the browser Monoglot Project 07.04.15
  8. 16 JavaScript §  Libraries have shorter life cycle §  Build

    chain not as stable as Maven/Gradle §  Native to the web §  Suited most for dynamic frontend driven projects with short lifecycle Java §  More stable than JavaScript §  More heavy that JavaScript §  Reusing Java resources §  Suited most for functional driven enterprise projects with long lifecycle Monoglot Project: The proper tool for the job 07.04.15
  9. 18 §  Using GWT (formerly Google Web Toolkit) §  Heavy

    optimizations based on the Java type system §  Java/GWT generated JavaScript usually smaller and faster than handwritten JavaScript Translate Java to JavaScript 07.04.15
  10. 20 §  2011-2012 §  Google shut down engineering in the

    Atlanta office §  à Pretty much the complete GWT team left Google §  Reduced marketing for GWT §  Competing frameworks inside Google §  No real Open Source project infrastructure §  Backward Compatibility §  Outdated stuff looks bad §  Frontend developers hate GWT J GWT? Is it still alive/relevant? - Why it’s considered dead 07.04.15
  11. 21 §  ~ 200 commits per month §  Google § 

    Still major development driver (75% of commits) §  (New) products using GWT: (upcoming) Calendar, Inbox, Sheets, Shopping Express, Flights, Android Play Console, Wallet, Groups, … §  Other companies: §  Red Hat (Errai, Uberfire, BPM), Vaadin, … §  ~150.000 monthly active SDK users GWT? Is it still alive/relevant? 07.04.15
  12. 22 §  Formed 2012 §  Transition to a real source

    Open Project Structure §  Lead the GWT project in major decisions GWT? Is it still alive/relevant? - GWT Steering Committee 07.04.15
  13. 23 §  GWT.create 2013 and 2015 with more than 600

    participants each GWT? Is it still alive/relevant? - Conferences 07.04.15
  14. 25 §  Big & active community §  GWT 2.x § 

    Java 8 (2.8) §  Incremental compiler (yay!) §  New debugger §  Improved interoperability with JavaScript §  Still: A lot of the old crap included §  Ambitious plans for future improvements (> 3.0) GWT? Is it still alive/relevant? – Current State 07.04.15
  15. 28 §  Driven by Red Hat §  Apache Software License,

    Version 2.0 §  https://github.com/errai/errai §  http://erraiframework.org Errai 07.04.15
  16. 32 §  Errai implements some Java EE 6 APIs for

    the browser §  CDI, JAX-RS, JPA, … 07.04.15
  17. 37 „Contexts and Dependency Injection” in Java(Script) 07.04.15 §  Java

    EE component model §  Dependency injection §  Event bus §  Scopes
  18. 38 „Contexts and Dependency Injection” in Java(Script) 07.04.15 @Inject private

    Caller<TodoService> todoService; §  Dependency Injection
  19. 39 „Contexts and Dependency Injection” in Java(Script) 07.04.15 @Inject @Created

    private Event<TodoItem> todoCreatedEvent; §  Firing CDI events
  20. 40 „Contexts and Dependency Injection” in Java(Script) 07.04.15 @Inject @Created

    private Event<TodoItem> todoCreatedEvent; public void createTodo(String text) { TodoItem createdTodo = new TodoItem(title); todoCreatedEvent.fire(createdTodo); } §  Firing CDI events
  21. 41 §  Catching CDI events is possible… §  … on

    Server §  … in the Browser §  Events are exchanged between server and browser and vice versa „Contexts and Dependency Injection” in Java(Script) 07.04.15 private void onTodoCreated( @Observes @Created final TodoItem createdItem) { /* ... */ }
  22. 44 Remote Procedure Calls 07.04.15 @Remote interface TodoService { /*

    ... */ } @Service class TodoServiceImpl implements TodoService { /* ... */ }
  23. 45 Remote Procedure Calls 07.04.15 @Remote interface TodoService { /*

    ... */ } @Service class TodoServiceImpl implements TodoService { /* ... */ } @Inject private Caller<TodoService> todoService; /* ... */ todoService.call(/* callback */).createTodo("todo"); /* ... */
  24. 47 Representational State Transfer 07.04.15 @Path("todos") interface TodoService { @POST

    @Consumes("text/plain") @Produces("application/json") TodoItem createTodo(String text); }
  25. 48 Representational State Transfer 07.04.15 @Inject private Caller<TodoService> todoService; /*

    ... */ todoService.call(/* callback */).createTodo("todo"); /* ... */ @Path("todos") interface TodoService { @POST @Consumes("text/plain") @Produces("application/json") TodoItem createTodo(String text); } §  Client code the same as in the RPC example!
  26. 50 Flexible Serialization 07.04.15 @Portable public class TodoItem { private

    boolean done; private String title; public TodoItem() {} public TodoItem(boolean done, String title){ this.done = done; this.title = title; } } §  No getter/setter for serialization needed
  27. 52 Flexible Serialization with immutable Entities 07.04.15 public class TodoItem

    { private final boolean done; private final String title; public static TodoItem create( @MapsTo("done") boolean done, @MapsTo("text") String title){ this.done = done; this.title = title; } } §  „@MapsTo“ can be eliminated with Java 8
  28. 54 HTML5 Templates 07.04.15 <!doctype html> <html> <link rel="stylesheet" href="styles.css">

    <form> <h3>Todo Item:</h3> <label for="title">Titel:</legend> <input datafield="title" id="title" type="text"/> <button datafield="submit">Todo anlegen</button> </form> §  Natural templating §  à Template can be opened in a plain browser
  29. 55 HTML5 Templates 07.04.15 @Templated public class TodoItemForm extends Composite

    { @Inject @Datafield private TextBox title; @Datafield private Button submit = new Button(); @EventHandler("submit") private void addTodo(ClickEvent e) { /* add the todo to the list */ } }
  30. 57 Bidirectional Data Binding 07.04.15 @Templated public class TodoItemForm extends

    Composite { @Inject @Bound @Datafield private boolean done; @Inject @Bound @Datafield private TextBox text; private TodoItem todoItem; @Inject public TodoItemForm( @AutoBound DataBinder<TodoItem> binder) { this.todoItem = binder.getModel(); } }
  31. 59 Navigation – Declaring Pages 07.04.15 §  Declarative Configuration § 

    Checked at compile time §  Java type system ensures that we do not have dead links @Page("example") public class ExamplePage extends Composite { /* ... */ }
  32. 60 Navigation – Declaring Pages 07.04.15 §  Declarative Configuration § 

    Checked at compile time §  Java type system ensures that we do not have dead links @Page("example") public class ExamplePage extends Composite { /* ... */ } @Page("example") public class TodoItemPage extends Composite { @PageState private String key; }
  33. 61 Navigation – With Anchors in Templates 07.04.15 @Page @Templated

    public class TodoItemPage extends Composite { @Inject @DataField private TransitionAnchor<TodoListPage> listLink; }
  34. 62 Navigation – With Anchors in Templates 07.04.15 @Page @Templated

    public class TodoItemPage extends Composite { @Inject @DataField private TransitionAnchor<TodoListPage> listLink; } <!doctype html> <a data-field="listLink">Zur ToDo Liste</a>
  35. 63 Navigation – Programmatically 07.04.15 @Page @Templated public class TodoItemPage

    extends Composite { @Inject private TransitionTo<TodoListPage> toListPage; }
  36. 64 Navigation – Programmatically 07.04.15 @Page @Templated public class TodoItemPage

    extends Composite { @Inject private TransitionTo<TodoListPage> toListPage; } /* ... */ toListPage.go(); /* ... */
  37. 66 Support of Mobile Hardware 07.04.15 @Page @Templated public class

    ProfileEditPage extends Composite { @Inject private Camera camera; } §  Based on Apache Cordova (PhoneGap)
  38. 67 Support of Mobile Hardware 07.04.15 @Page @Templated public class

    ProfileEditPage extends Composite { @Inject private Camera camera; } private void onBatLow(@Observes BatteryLowEvent) { /* warn the user */ } §  Based on Apache Cordova (PhoneGap)
  39. 69 §  Challenges of rich internet applications §  Integration of

    front end backend §  Code duplication between client and server §  Working on large code bases with large teams §  GWT is alive J Summary 07.04.15
  40. 70 §  Use the best tools and standards §  HTML5

    and CSS for layout §  Java for enterprise development §  Share data model and validation logic - Don’t repeat yourself! §  Bust the boilerplate §  It’s Java! §  Type-safe §  Java tooling (IDE, analysis) §  Java libraries (runtime, testing, …) Summary – How Errai Helps 07.04.15
  41. 71 Innovation Implemented. 07.04.15 mgm technology partners GmbH Frankfurter Ring

    105a 80807 München Tel.: +49 (89) 35 86 80-0 Fax: +49 (89) 35 86 80-288 http://www.mgm-tp.com Prag München Berlin Hamburg Köln Nürnberg Grenoble Leipzig Dresden