Errai: The browser as a platform

Friday, July 1, 2016

Errai 4.0.0.Beta2 released!

Salutations!

Today we're happy to announce the release of Errai 4.0.0.Beta2. This release includes lots of little fixes and enhancements including:
  • The EmbeddedWildflyLauncher for Super Dev Mode has been upgraded to use WildFly 10
  • Errai Navigation has new annotations for linking native anchors to Errai Navigation pages
  • Improved code-generation performance
  • Better support for declarative data-binding to native DOM elements
  • An injectable ManagedInstance for dynamically creating bean instances that manages the instances' life-cycles
Below we'll explain what some of these changes mean before talking about next steps.

WildFly 10 Upgrade

The EmbeddedWildflyLauncher now support WidFly 10+. Because of API changes in WildFly, it was not possible to maintain backwards compatibility with WildFly 8. That means that you have two options when upgrading Errai to 4.0.0.Beta2.

Upgrading to WildFly 10 (Recommended)

If you use the same WildFly configuration shown in the Errai Tutorial then you need only upgrade the as.version property to 10.0.0.Final. If you have any other configuration, just make sure that the errai.jboss.home system property in your Super Dev Mode configuration points to the root of a WildFly 10 installation.

Don't Upgrade errai-cdi-jboss

If you can't migrate to WildFly 10 right away, you can use an older version of errai-cdi-jboss (which contains the launcher) while still using the newest beta release for all other Errai jars.

Errai Navigation Links with Native Anchors

Errai Navigation has two new annotations that you can use on native Anchors for linking to Errai Navigation pages:
  • org.jboss.errai.ui.nav.client.local.api.TransitionTo
  • org.jboss.errai.ui.nav.client.local.api.TransitionToRole

These annotations are meant to replace the widget-based TransitionAnchor. Below we show them used in an Errai UI templated bean.

The first anchor links directly to the FAQPage while the second links to the page with the DefaultPage role. As with the previous transition anchors, Anchors with TransitionTo or TransitionToRole are validated at compile-time.

Better Data-Binding Support for Native DOM Elements

There were two issues with declarative data-binding of native elements in Errai 4.0.0.Beta1:
  • @Bound on a native element would fail in some cases for beans that were not @Templated
  • @Bound(onKeyUp=true) on an input element (TextInput, NumberInput, etc.) was not supported (and would cause compilation errors)
Both of these issues are fixed in 4.0.0.Beta2, moving Errai two small steps closer to the goal of GWT widget-free UI development.

Creating Beans Dynamically with Managed Life-Cycles

Errai supports CDI's Instance<T> for dynamically creating bean instances, but this API has some practical issues:
  • An instance created by an Instance<T> is managed by the caller. The caller is responsible for destroying the bean, which can lead to memory leaks.
  • Calling destroy on an Instance<T> destroys a bean regardless of its scope. But usually it is only desirable to destroy @Dependent beans, since @ApplicationScoped beans tend to be used throughout the entire runtime of an application.
Errai 4.0.0.Beta2 includes a new ManagedInstance<T> interface with similar methods but slightly different semantics that aim to simplify dynamic bean creation:
  • The destroy method on ManagedInstance<T> destroys @Dependent instances and is a no-op for all other scopes.
  • ManagedInstance<T> has a destroyAll method that destroys all @Dependent instances created by it.
  • When a ManagedInstance<T> is destroyed, its destroyAll method is called. A ManagedInstance<T> is destroyed when the bean it is injected into is destroyed.
In case the significance of that last point isn't immediately clear, this means that every dynamically created @Dependent instance from ManagedInstance<T> is cleaned-up when the type that injected that ManagedInstance<T> is destroyed. This avoids memory leaks and boiler-plate in short-lived components that create dynamic instances (like lists of UI elements).

Next Steps

In the coming weeks here are some of the features and tasks we will be working on:
In the interim, please try out Errai 4.0.0.Beta2 and tell us what you think.

Happy coding!

3 comments:

  1. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    Java Training in Chennai

    ReplyDelete