Errai

The browser as a platform

Harald Pehl · 25.03.2015 · JUGF

Harald Pehl

Senior Software Engineer

Another Web Framework?

HTML5

Performance

More Logic in the Browser

Offline

Multiple Devices

Java Please!

Typesafe Language

Refactoring

Testable

Code Analysis

Mature IDEs & Tools

Frameworks & Libraries

WT

Java to JavaScript Compiler

Generates highly performant and optimized JS

Cross-browser support

Development Mode

Debug client & server code in you IDE

Isn't GWT dead?

Active open source project

100k+ community users

1000s of internal Google employees

Popular apps using GWT (Inbox, Google Flights, Google Spreadsheets)

JsInterop and Java 8 support coming

They say it's complicated


mvn archetype:generate \
    -DarchetypeGroupId=org.codehaus.mojo \
    -DarchetypeArtifactId=gwt-maven-plugin \
    -DarchetypeVersion=2.7.0
            

Demo

UI Templates Java EE APIs JAX-RS CDI MessageBus JPA Mobile Events HTML5 Client Server Java GWT Security RPC Data Binding Navigation

Get Started

Use https://github.com/errai/errai-tutorial/ as a template

Make sure to take a look at the Errai Reference Guide

Ask the developers at #errai on freenode

Errai TodoMVC

Simple todo manager based on http://todomvc.com/

Code is available at https://github.com/hpehl/errai-todomvc

Demo

Errai CDI - Events

Sender

@Inject @Updated
private Event<Todo> updatedTodoEvent;
...
button.addClickHandler(event -> updatedTodoEvent.fire(todo));
                
Receiver

public void onUpdatedDocument(@Observes @Updated Todo todo) {
    // receive updated todo
}
                

Errai CDI - Producer

Producer

@Produces @Supported
public MyBaseWidget createWidget() {
    return (Canvas.isSupported()) ? new MyHtml5Widget() : new MyDefaultWidget();
}
                
Consumer

@Inject @Supported
private MyBaseWidget widget;
                

Demo

RPC

Shared

@Remote
public interface HappyService {
    boolean isEveryoneHappy();
}
                
Server

@Service
public class HappyServiceImpl implements HappyService {
    public boolean isEveryoneHappy() {
        return true;
    }
}
                
Client

@Inject
private Caller<HappyService> happyService;
...
happyService.call(response -> ...).isEveryoneHappy();
                

JAX-RS

Shared

@Path("customers")
public interface CustomerService {
    @POST
    @Consumes("application/json")
    @Produces("text/plain")
    public long createCustomer(Customer customer);
}
                
Client

@Inject
private Caller<CustomerService> customerService;
...
customerService.call(response -> ...).createCustomer(customer);
                

Demo

Demo

Get in touch!