Errai: The browser as a platform

Saturday, January 26, 2013

Do you use Errai? Tell us!

We have a growing community of users, and we want to know who you are! If you haven't already, put us on your Ohloh stack.

Secondly, remember that you can always hop on IRC at on channel #errai to get help/support or just to mingle with Errai community!

Thirdly, this is the time to start hearing feature requests for Errai 3.0 as we've now begun that effort in earnest.

Happy coding!

Friday, January 25, 2013

Errai 2.2.0.Final released!

Thank you for the feedback and bug reports in the last month. We have just released Errai 2.2.0.Final! Check out the release notes for all the details!

Now we're all looking forward to get back into R&D mode and work on some exciting new features for Errai 3. Stay tuned for updates on client-server data synchronization and more upcoming mobile features.

Here's a screencast demoing the biggest new features in Errai 2.2: HTML5 templating, data binding, and client-side JPA persistence. Also make sure to check out the new page navigation module!

Errai To-Do List from JBoss Developer on Vimeo.

Monday, January 14, 2013

Timing your methods!

Errai 3.0 development continues to move forward unabated. One new feature that I worked on today is something I've being pining for recently.

When you're developing rich web apps, one thing you often find yourself working with are timers. 

They enable animations and timeout logic in your application logic. But since Errai manages beans inside your browser, it seemed like an elegant solution that fits in nicely with other beany features was in order. 

Enter, the @Timed annotation!

This example shows a method that is part of a bean, which we have annotated with the @Timed annotation. In this case we have configured the timer to fire every one second.

You get all the benefits of working in a managed bean environment. For instance, when the bean is destroyed, so to is the timer, implicitly.

Anyways, this just went directly into the Errai 3.0 branch, and if you want to play with it, get forking!

Friday, January 11, 2013

Implicitly @Dependent. Explicitly Awesome!

One common problem that keeps catching people off guard using Errai UI and its hip companion framework, Errai UI Navigation, has been that @Templated and @Page beans have required explicit-scoping in order to work correctly.

It turns out that you almost always want such beans to be of the @Dependent scope. But if you know a little bit about CDI, you might be saying to yourself: well, all non-explicitly scoped beans are of the @Dependent scope! 

Well, yes. This is true. But Errai throws a bit of a curve-ball here. Because while Errai respects this semantic when it comes to static injection, it does not respect it when it comes to dynamic injection / dynamic lookup.

The reason for this is straight-forward. When Errai compiles your CDI code magically down to JavaScript (via the GWT compiler), it prunes all the bean wiring code from non-explicitly scoped beans. It does this as a way of minimizing the amount of dead code that ends up being compiled. 

So, for example, if we respected the CDI specification strictly, we'd end up having to create bean wiring code for things like ArrayList, HashMap, LinkedList, StringBuilder, etc.  Instead, we allow you to @Inject those dependent beans directly as you might in a fully compliant CDI container. But we don't produce the code to allow them to be dynamically produced at runtime.  

So, for Errai, implicit dependent beans are a compile-time feature. Not a runtime feature.

But wait! It turns out there's a common need to dynamically lookup @Dependent beans in Errai applications. Widgets, for instance, are more often than not, of the @Dependent scope. And many widgets you want to instantiate many times, dynamically. Which is a perfect fit for the @Dependent scope. 

So to allow you to overcome the limitation we impose, you can annotate your bean with a @Dependent annotation. This explicit scoping is treated as signal that you want to interact with the bean via the bean manager. And that's why you've had to explicitly scope all your @Templated and @Page beans up until now.

But as it turns out, we've changed the rules. In the absence of an explicit scope, Errai will now consider the use of either of these two annotations to mean the same thing as an explicitly-scoped @Dependent bean.

The good news is that this improvement will be directly available in the next 2.2 release. And in final.

Hopefully this improvement makes your coding experience a little bit more pleasant. It has for us.

Thursday, January 10, 2013

ErraiBus clusters natively!

Christian and myself burned some midnight oil the past few days in order to get ErraiBus's new native clustering support up and running.

Some of our users have been looking for this for some time as ErraiBus has been somewhat limited in clustered environments and required the creation of JMS Queues and such to handle global broadcasts in a cluster.

People wanted something that would "just work" without having to worry about the topology of user sessions relative to whatever random server a load balancer might move a user to.

As I just mentioned, really smart engineers have managed to work around the limitation that each bus is not aware of any other buses in a cluster. And even then, it's only a problem for a certain class of applications. But the whole point of ErraiBus was to be stupid easy to use.

Therefore, tonight in the 3.0 branch we committed a new ClusteringProvider implementation that leverages the ever-so-awesome JGroups.

It's pretty easy to use for basic clustering scenarios. Basically you add the following two lines to the file.

Yeah, that's about it. JGroups will startup with the bus and use multicast to find other buses.

So if you're interested in testing it yourself, hurry on over to the 3.0 branch, give it a clone and build it with Maven. If that's too much work, don't worry, we'll have a pre-release coming very shortly.

Tuesday, January 8, 2013

Mobile Errai

Creating an application for mobile is challenging and GWT is very good to use in this space, because it optimises for the browser and keeps the downloads small. But still there is this big initial download that users of your application need to do (all the html and javascript). Also if you are going to create a mobile application you want to be able to use the additional features that a phone has, in a convenient way.
This is where Errai-Cordova comes in. As you can get from the name it uses Cordova to create an application that can be installed easily on mobile devices. Cordova is like a little web server and a web browser bundled into a mobile app. So now, when your application gets installed, the user will already have all of your front-end. To be able to use your backend you'll have to do some configuration.
In the class org.jboss.errai.example.client.local.Config you need to specify the address of your backend server like so:
Now you can create some responsive html and have it behave nicely on differently sized devices. I'm not that good in designing something that looks very nice, but there are some really nice things that you can make. Take a look at and make your browser window smaller to simulate looking at this site with a phone or a tablet.
Finally using the capabilities of the phone, like the camera or accelerometer, you can inject them in a true errai fashion.

Take a look at the demo project on github for a working example.
This is the sneak peak of what's to come, hope you like it!