If you are new to Errai, the quickest way to get started is via the archetypes described in our Getting Started guide.
New in 2.1
We're calling these new features in 2.1 "preview" because we want a chance to incorporate your feedback before we lock down the APIs in 3.0. We crave your input: share your use cases, feature requests, and of course pull requests.
Of course, this code does the same thing on the client as it would on the server:
Get your hands dirty by playing with the demo, which you can find on GitHub.
In Errai 2.1, we're adding a new option to the mix: Errai UI. Errai UI gives you declarative layout through templates that are valid HTML 5 documents, paired with Java classes that imbue behaviour into them. Of course, you get compile-time checks to make sure everything lines up properly. We want to help you avoid unpleasant surprises at runtime!
Here's an Errai UI template:
The only special bits are the data-field attributes. These line up with field names in the companion Java class, like this:
To handle events, simply annotate a method with @EventHandler("DataFieldName"). The method should take an argument of the event type you want to receive. Errai UI will ensure the source node sinks the appropriate events, and it will deliver them to your method each time they happen.
To learn more, check out the ErraiUI demo, and also read through Errai UI's reference guide.
But wait! There's more!
There are two more new Errai modules that go great with Errai UI: data binding and navigation.
Model-View Data Binding
Errai Data Binding lets you bind property values in your model objects to widgets in your UI.
To make a model object amenable to having its properties bound, annotate it with @Bindable:
Then to establish data bindings to UI widgets, use the fluent configuration API:
Declarative Data BindingWhen Errai Data Binding is used together with Errai UI templates, you can skip the fluent API and simply declare "auto-bindings." Going back to the ItemForm example:
By injecting an @AutoBound DataBinder and adding the @Bound annotations on the widgets, we get a declarative approach to data binding. With the above code snippet in place, it will always be true that itemBinder.getModel().getName().equals(name.getText()).
Errai data binding also allows custom converters, wrapping existing model objects, and more. See the reference guide for all the juicy details!
The third new UI-related feature in 2.1 is Errai Navigation. Errai Navigation adds a decentralized, declarative configuration mechanism to GWT's built-in History facility. This allows back-button and forward-button navigation, plus bookmarkable locations within your app. And since the configuration is declarative, it even produces navigation flow graphs like this at compile time:
The navigation system simply manages the contents of a panel (a div element in the DOM): based on what comes after the # in the location bar, the contents of that div change. Typically, in your app's entry point, you would add that panel to a large, central region of the document. Headers, footers, and sidebars can remain outside of this div, which allows them to stay in place when the user navigates between pages.
As an example, if you want the URL http://example/my-app/host-page.html#FunPage to cause the page body to contain an instance of your FunPage widget, you would do the following:
Pages are CDI beans, and the navigation obtains instances from the client-side bean manager when needed. So the above implicit-scoped bean would be newly instantiated each time the browser's URL bar changes to http://example/my-app/host-page.html#FunPage. If you'd prefer one instance of FunPage to hang around for the life of the app (simply appearing and disappearing based on the current URL fragment,) just annotate it with @ApplicationScoped.
But what good are pages without links between them? To make links between pages, inject TransitionTo instances like so:
These links make up the arrows in the navigation graph that's produced at compile time. The type parameter controls the widget (CDI bean) type that provides the page contents, and the field names are the label text on the arrows.
Of course it goes without saying that Errai Navigation goes great with Errai UI templates: a @Templated widget can also be a @Page.
Improved Since 2.0
Client-side Remote Call Interceptors (JAX-RS and RPC)
Sometimes you need a chance to tweak a request just before it's sent to the server. For example, maybe you need to add special authentication headers to certain REST requests. Or maybe you want to short-circuit requests when you already have locally-cached data. Previously, you would have had to give up on the typesafe Errai JAX-RS Caller<T> interface for those requests, and fall back to RequestBuilder.
Well, starting in Errai 2.1, you can intercept, inspect, modify, and even cancel any Errai JAX-RS and Errai RPC request. See the documentation for the details and example code.
GWT 2.5 Compatibility
In Errai 3.0, we do plan to bump up the minimum requirement to GWT 2.5, so get testing!
Code-and-Refresh: Better Than Ever
Additionally, the dynamic (server-side) marshalling system in Errai 2.1 is now run through the same set of tests as the statically-compiled marshallers. This means you can stick to dynamic marshalling at development time, with two big advantages: firstly, it makes dev mode setup simpler (especially when using an external web server); secondly, it behaves well in conjunction with server-side hot reload products such as JRebel.
Errai Marshalling: Now Compatible with Jackson
The user guide has a section that details how to enable Jackson compatibility mode in the REST client.
Try itNow that 2.1.0.RC2 is out in the wild, I hope you will take the time to test your Errai app with it. We hope to go final soon, so get those bug reports and pull requests in before it's too late!
And if you're new to Errai, the quickest way from-zero-to-Errai is our Getting Started guide.