Final Version of AngularFaces 2.0 Published

Fork me on GitHubIt was a hot summer day when I was sitting in the garden and started to dream. Wouldn’t it be nice to add AngularJS to JSF?

Today it’s a sunny day too, I’m sitting in the garden again and AngularFaces 2.0 is finished (it’s even available on Maven Central). Now it’s possible to use AngularJS without abandoning JSF. Even better: it’s very simple, and AngularFaces 2.0 has much more in store for you. It adds a couple of features beyond AngularJS, such as bringing the Bean Validation annotations to the client and helping you to target an international market by reducing the boiler plate code needed to translate an application. AngularFaces is worth a look if you don’t want to involve yourself AngularJS programming.

Continue reading “Final Version of AngularFaces 2.0 Published” »

AngularFaces 2.0 RC4 Published

Fork me on GitHubThe final release of AngularFaces 2.0 is coming near! The latest – and possibly last – release candidate RC4 has been published today. Here’s what’s new and noteworthy about the version:

  • Reduced requirements on the Java version: Java 6, 7 and 8 are supported. The binaries in the distribution folder are compiled with Java 6.
  • You can now use traditional JSF AJAX requests with AngularFaces (although it’s not advisable to do so, because AngularJS doesn’t seem to support this).
  • Improved compatibility to Internet Explorer 11 (and probably older versions as well, but since I’ve updated my PC to the latest version, I can’t really tell).
  • Several common HTML tags can now be used without preceding “h:”.
  • <input> can now be used without “type” attribute. The type is derived from the JSF bean. This isn’t exactly a new feature: AngularFaces supports the same feature for <h:inputText> since a long time. The news is that also the native HTML5 <input> is supported.
  • Client-side error messages use the PrimeFaces design in PrimeFaces views (and the simpler Mojarra design otherwise).
  • AngularFaces input fields can now display boolean JSF bean attributes (and are displayed as checkboxes).

Work on the manual on is also progressing nicely. The same applies to the demo applications.

As usual, you find the updated jar file and two demo war files on the AngularFaces dist folder on GitHub.

Java 8 Update 20: String Deduplication

Remember my last April prank? I span a yarn about the great way Oracle managed to squeeze every conceivable String into a 64-bit number. Funny thing is my vision comes sort of true. Of course, not the way I claimed. That was nonsense meant to be easily seen through (“There are only so many Strings a gal or a guy can think of – so everything you have to do is to assign them a 64-bit number”). But it’s true that a lot of work at Oracles’ is dedicated to optimize String management.

Java 7 Update 6 improved the speed of String.substring() by sacrificing a little memory efficiency (see my article Recent Improvements of Java’s String Implementation). Java 8 Update 20 takes the opposite approach: it sacrifices a little CPU efficiency in order to reduce memory footprint. On the long run this should reduce the strain on the CPU, too. In other words: most real worlds programs should run faster.

Everybody who’s analyzing a Java program in a profiler can’t avoid noticing: Java programs create incredible quantites of character arrays. Most of them are part of String objects. Java represents its String as objects, meaning there’s a pointer to a character array. That’s not exactly the most efficient way to represent a sequence of characters. It’s just what you get if you want to represent a String as an object instead of defining it as a native primitive type. However, the developers of Java got aware of the problem a long time ago, so they invented the String.intern() method. In general, it’s a bad idea to call this method by yourself (because you’re trying to outperform the JVM’s optimization), but sometimes it reduces your application’s memory footprint tremendously.

Putting it in a nutshell, String deduplication is a clever way of calling String.intern() as part of the garbage collection. Since Java 8 U20 the garbage collector recognizes duplicates String and merges them. As mentioned above, this costs some CPU power, but it shouldn’t be much of a concern because the garbage collector runs in its own thread. Plus, on the long run the reduced memory footprint makes the garbage collector run faster.

There’s a discussion on reddit indicating String deduplication really works, but sometimes you have to adjust the JVM parameters. I suppose that’s one of the reasons why the feature isn’t activate by default yet. You have to activate manually by starting the JVM with the parameter

-XX:+UseG1GC -XX:+UseStringDeduplication

Still, I sometimes wonder why a Java String has to be an object. Back in the seventies or the eighties, when the first languages became powerful enough to represent a String by means of the language instead of defining it as a primitive type, it quickly become a fashion to do so. Probably there are other reasons, but I always had the impression language designers considers this a sign of their language’s maturity. But being able to express a String as a library object doesn’t mean to have to do so. If Java were to use zero-terminated character arrays (the way BASIC does) or if it were to use a character array with a preceding length byte1, hardly any developer would notice. But the implementation gets rid of a pointer, simplifying memory management and garbage collection. The only convincing advantage of making Strings part of the language libraries is the ability to derive custom classes. Sadly, the Java developers prohibited this very early in the Java history by making String a final class. They did it for a good reason – but still, it’s a pity. Groovy’s GStrings show what you can do when you allow to derive from Strings.

That said, I’d like to point you to Java Performance Tuning Guide. They’ve written an in-depth article about Stringdeduplication.

Dig deeper:

Java Performance Tuning Guide on String deduplication
discussion on reddit on the topic (well, one of them – possibly the most interesting one)

  1. or a 64-bit word in the age of Gigabyte memories – and the characters should be at least 16-bit to support UTF-16. I used “byte” and “character” as a figure of speech. Is there a catchy word for 16 or 32-bit integers?

JSF 2.2 HTML5 Cheat Sheet

I’ve read a lot about the new JSF 2.2 HTML5 input fields, but until today I didn’t realize I hadn’t read a comprehensive introduction about this feature. I used to be happy with the short examples I was presented at conferences. However, there’s more than just <input type="text" jsf:value="#{my.favoriteBean.attribute}" />. As it happens, the documentation hides in plain sight. The JavaEE Javadoc tells you everything you have to know about the Mapping between HTML tags and JSF components. For the sake of convenience, this article summarizes the key points.

The general idea is to enable a web designer to design your JSF page without running a server. So it’s native HTML, and it should display nicely in a browser if opened as a simple HMTL file. Putting it in a nutshell, renaming a JSF file from *.xhtml to *.html doesn’t modify the design of the page.
Continue reading “JSF 2.2 HTML5 Cheat Sheet” »

AngularFaces 2.0.0 RC3 Published

Fork me on GitHubRelease candidate 3 of AngularFaces 2 has been published. Basically, it’s a bug fix release. Here are the release notes:

  • Bugfix: compatibibility with PrimeFaces <prime:datatable>
  • Bugfix: AngularFaces now copes with bean attributes, even if they are Strings (quite a funny bug, if you take in mind Strings are usually tested first).
  • Improved translation support (now includes the attributes “header” and “headertext”)
  • Bugfix: Labels and messages aren’t added automatically if the JSF view designer already defined a label an/or a message
    • In addition, I’ve started to write a tutorial. To read the tutorial, go to The example projects accompanying the tutorial are on GitHub. At the time of writing, the first two steps (“Bootstrapping” and “Labels and Messages”) of the tutorial are finished (plus a couple of sketches of the remaining chapters).

AngularFaces 2.0 Embraces Both HTML5 and PrimeFaces

Fork me on GitHubNow that’s a surprise: AngularFaces becomes more powerful by getting rid of it’s widgets. Quite a development for JSF widget library.

Instead of defining its own widgets AngularFaces 2.0 pimps up widgets provided by other widget libraries. In particular, it adds AngularJS to the new JSF 2.2 HTML5-style widgets. But of course it doesn’t stop there. It’s also compatible to the widgets of Mojarra and MyFaces and to many PrimeFaces widgets. Plus, it allows AngularJS to modify almost every JSF attribute.

Update Sept 16, 2014:
In the meantime I’ve released the final version of AngularFaces 2.0, so you may also be interested in the announcement of the final version.

What’s in store for you

You may already have guessed it: AngularFaces underwent a profound overhaul during the last three weeks. Now it’s much more versatile and much more “Angular”. Let’s summarize the key points of AngularFaces 2.0:

  • It integrates AngularJS and JSF seamlessly. The difference between the two technologies becomes blurry. It doesn’t matter if you modify an attribute on the server side or in your AngularJS code. Both options are available to you. You can even do both, if you insist.
  • In particular, JSF bean attributes are mapped into the AngularJS model. The mapping works in both directions, of course: the next request transfers changes made on the client side back to the server. After processing the user input the server update the AngularJS model again.
  • Bean validation attributes (JSR 303) are evaluated on the client side by AngularJS (resembling the Client Side validation of PrimeFaces).
  • Labels and error messages are added automatically to your input field (unless you tell AngularFaces otherwise).
  • AngularFaces 2.0 makes internationalization much less scary. Translating your application into another language becomes very simple.
  • AngularFaces 2.0 takes a new approach to AJAX. Mind you: you don’t need server side rendering when you’re using powerful Javascript widgets, so I reduced the AJAX responses to the attribute value updates, making them fast and slim.
  • Every AngularJS attribute is treated as a pass-through attribute. You don’t have to declare it explicitly as a pass-through attribute. For instance, ng-show, ng-hide and many more can be used in the JSF file the way you’d use it in a pure AngularJS application.

As a result, AngularFaces views are pretty fast, contain very little boiler-plate code and may look almost like a native AngularJS page. Everybody coming from Javascript programming will get to speed in virtually no time. However, transition from JSF is smooth: you’re free to write a traditional JSF page with a few AngularJS additions.
Continue reading “AngularFaces 2.0 Embraces Both HTML5 and PrimeFaces” »

JSF 2.2 and PrimeFaces 5 on Spring Boot

Fork me on GitHubRecently I reported about Spring Boot (see Application Servers are dead! (Sort of)), an interesting approach to embed your application server into your application instead doing it the other way round.

However, Spring Boot is a fairly new technology, so the documentation is still work in progress. Most of the documentation is great, but there are still sentences like

Applications that are not already Spring applications might be convertible to a Spring Boot application, and the guidance above might help, but your mileage may vary.

Most JSF applications clearly fall into this category. So I’ve prepared a JSF template project to spare you some of the mileage. Currently there’s a simple simple PrimeFaces project and a more advanced project demonstrating Spring and JSF scopes.

To make things more interesting, I added Gradle and JSF custom scopes to the equation.
Continue reading “JSF 2.2 and PrimeFaces 5 on Spring Boot” »

Newflash: Java, UTF-8 Surprises and Character Encodings

Did you know characters don’t always fit into chars?
Did you know String::length() does not always return the number of letters of the String?
Did you know you can’t reliably read a text using a ByteArrayInputStreamReader?
Did you know many characters have more than one Unicode encoding?

The latter you should know, at least if you’re concerned about writing a secure web application. Hackers sometimes hide their malicious code by using ambiguous UTF-8 encodings. If the request is interpreted correctly, it simply contains an odd character. But if your application interprets the request as simple ASCII code, it contains executable Javascript code. The “<” sign can be hidden as a modifier to a unicode character, so a (careless?) firewall doesn’t recognize it as the start of malicious code.

Before leading you to McDowells great “guide to character encoding”, I’d like to show a couple of interesting characters to you:

  • The letter A is encoded in UTF-8 as 0x41. That’s simply good old 7-bit ASCII code.
  • The french letter é (as in écouter) is part of many 8-bit extensions of ASCII. In UTF-8 it’s encoded as 0xE9.
  • However, it also can be constructed as a combination of “e” and the accent “´”. That amounts to 0x65CC81 in Unicode. That’s the first example of the three byte representation of a character.
  • Characters can become as complicated as क्तु. That’s a 12 byte encoding in UTF-8: E0A495 E0A58D E0A4A4 E0A581. As far as I can tell, that’s a base character followed by three modifiers.

The last character doesn’t fit into a Java char, and "क्तु".length() yields 4 – albeit it’s considered a single Devenagari letter.

There’s a lot more information on Java character encoding on McDowells “exhausting, but not exhausting” article Java: a rough guide to character encoding.

Useful PrimeFaces DataTable Events

I always used to skip over page 167 of the PrimeFaces 5 manual. That’s too bad: it’s an exciting page. It’s a list of the events a <p:dataTable> can fire. That’s no less than 19 interesting events.

Quick reminder: what are JSF events?

Chances are you already know the concept of JSF events from the <f:metadata> section of your JSF applications. Strictly speaking, the core JSF events I’l describe next belong to a different family than the events fired by the data table. They’ve got a different API. But still, both concepts are similar enough to mention them in the same article.

A standard JSF event, preRenderView, is frequently used together with view parameters. Doing so, your parameterized JSF page can be stored as a bookmark in the browser, much like Amazon allows you to simply copy the link of the book review you’re currently reading and send it to your friends:

        <f:viewParam name="keyword" value="#{catalogController.keyword}"/>
        <f:event type="preRenderView" listener="#{catalogController.doSearch}"/>

Continue reading “Useful PrimeFaces DataTable Events” »

How to Run the Eclipse Formatter From the Command Line

Today I’ve dug out an Eclipse 3.2 article that’s seven years old and is still valid. Considering how much Eclipse has changed since 2007 that’s pretty astonishing. So, if you want to know how to format an entire Java Eclipse project in no time, you may ask Peter Friese. Of course you’re invited to read on instead and learn some additional hints.
Continue reading “How to Run the Eclipse Formatter From the Command Line” »

Microservices – The New Silver Bullet?

Recently microservices are getting popular in the Java world. The general idea is our applications have become too complex. Better split them into smaller chunks, small enough to swallow for a small team or even an individual. They have “to be small enough to fit in your head”.

Actually, this idea is far from being new. When functions, classes, modules, portlets, SOA services and business processes were invented, people used pretty much the same words to advocate the new idea. Microservices add a new twist in that they contain the GUI, and in that every microservice uses it’s own database. The application is sliced vertically (as opposed to the horizontal slicing imposed by the MVC model). The result is a small library that can be deployed independently. The application consists of a collection of largely independent microservices working together.
Continue reading “Microservices – The New Silver Bullet?” »

Application Servers Are (Sort of) Dead!

Recently it crossed my mind there’s something wrong with Java application servers. You know, our team is still using them the way they’re meant. The way they were originally meant. We’ve got many applications running on a common application server that’s managed centrally.

I’m told we’re one of the last companies to do so. These days, most companies dedicate an entire application server to a single application and put them in a virtual machine.

In other words, application servers have become part of the application. Originally, it was meant to be the other way round, and that’s why Eberhard Wolff claims application servers are dead. His JAX talk was a real eye-opener, by the way. He expressed the thoughts that ware already lingering in the subconscious part of my mind. As usual, I’ll mention a few key points of his talk in this post, plus a few thoughts of my own. If you’re interested in the entire talk, have a glance at his slides. He also published an article in the Java-Magazin 7.2014 (in German language, and as far as I know, only available in print).

So what’s wrong with the original idea of applications servers? Let me put the question differently: Have you ever seen an application server that runs out of the box, without being modified?
Continue reading “Application Servers Are (Sort of) Dead!” »

BabbageFaces 1.0 RC2 Now Available for Download

Fork me on GitHubMy guts tell me BabbageFaces is ready to be released into the wild. Most of the time that’s a reliable measure. Today I’ve tested it with the new PrimeFaces 5 showcase. BabbageFaces passed the test without problems. There’s also a decent showcase example containing most of the elements of a typical business application, running both on Apache MyFaces and Mojarra. I’m optimistic all that’s missing is a couple of source code comments, tidying and documentation to call it a final version.

The showcase demo also shows BabbageFaces allows you to stop scattering ids all around your JSF code just to make AJAX efficient. BabbageFaces compares the response with the current DOM tree and sends only the minimum set of changes to the clients. If network load is giving you headaches, BabbageFaces may be your tool of choice. It reduces network traffic. At the same time it simplifies the programming model.
Continue reading “BabbageFaces 1.0 RC2 Now Available for Download” »

Value Types: Revamping Java’s Type System

This morning Brian Goetz revealed interesting news at the end of his talk at the JAX conference. Oracle is considering to extend Java’s type system. Did you ever wonder why there are no call by value parameters in Java methods? Why there’s no Array<int> in Java? Why functions return one – and only one – value at a time? Why there are no tupels in Java? Why arrays are created in such a weird way, making them effectively scattered all around the memory? Brian Goetz told us they might fix all this after adding value types to the language, which allow for a efficient implementation of these ideas. Truth to tell, he didn’t really promise value types. In particular, he says Java 9 will almost certainly not include the feature. However, judging from the quality and level of detail of his “State of the Values” paper I’m positive they are going to make it into a future version of Java.
Continue reading “Value Types: Revamping Java’s Type System” »

Announcement: BabbageFaces 1.0 RC1

Fork me on GitHubToday I’ve uploaded the new showcase demo of BabbageFaces.

After fixing every bug I know of, I made up my mind to call the current version a release candidate. Now it’s up to you: download BabbageFaces and tell me whether it works with your application.

I still recommend to use the source code version from GitHub because then it’s easier to trace down potential bugs. However, you can also download the distribution file from the distribution folder on GitHub.

Please let me know about your experience. Report errors as a comment at the end of this page (don’t forget to provide the source code so I have a clue what’s going wrong!). But of course I’d also like to hear from you if you’re using BabbageFaces successfully :). In any case, be prepared to receive an e-mail if I need further information to reproduce your bug or to answer your question.

Newsflash: Can You Rely on System.nanoTime()?

If you’re like me, you’re concerned about your application’s performance. So you’re familiar with profiling your application.

The simplest way to measure your application’s performance is to time how long a method call takes. Most of you probably know System.currentTimeMillis(), but there’s a better alternative:

public long measure() {
  long startTime = System.nanoTime();
  return System.nanoTime() - startTime;

System.nanoTime() is a great function, but one thing it’s not: accurate to the nanosecond. The accuracy of your measurement varies widely depending on your operation system, on your hardware and on your Java version. As a rule of thumb, you can expect microsecond resolution (and a lot better on some systems).

Alexey Shipilev wrote a great article on the dos and don’ts of measure performance. Among other things he shows how multithreading can spoil the accuracy of performance measurements, reducing the resolution of System.nanotime() to 15 milliseconds under averse conditions.

Newsflash: React Speeds Up AngularJS Rendering

Today I’ve read about a small but interesting framework called React.js that convinced me to start a new series on this blog. Newsflashes are small articles, just two or three sentences, describing an interesting idea and providing a link to read on. They are less thoroughly researched than the full-fledged articles of Instead I’ll go with my guts to choose interesting bits of information.

React is a lightweight Javascript framework focusing on the UI. According to the project page, using a virtual DOM difference algorithm makes it very fast. Thierry Nicola decribes in his article how to combine AngularJS and React to make your AngularJS application faster.

While the effect is impressive, chances are you’re going to benefit from React without having to use it yourself. My bet is many frameworks, possible even browsers, are going to use virtual DOM by default.

What’s New in PrimeFaces 5?

PrimeFaces 5.0 is going to be released any day now – most likely tomorrow (May 5, 2014). Çagatay Çivici, Thomas Andraschko and a few others invested a lot of work in the new version: The source code repository lists more than a thousand commits since the last version, PrimeFaces 4.0, which in turn has been released only half a year ago. So it’s time to look what’s happened since October, 3 2013.
Continue reading “What’s New in PrimeFaces 5?” »

AngularFaces 2: Even Better Steroids for JSF

Fork me on GitHubAngularJS and other fancy Javascript frameworks stir up the Java world. The Java world has been dominated by server side framework for more than a decade now. Times they are changing. Now everybody’s moving to the client side. The server’s reduced to a faint memory, such as a REST service.

Everybody? Not quite. A lot of developers want to steer a middle course. That’s AngularFaces for you.

By the way, the interest in AngularFaces is tremendous. The AngularFaces announcement has become the second most read article of, being read a hundred times each day.

So I decided AngularFaces needs a strong grounding. You know, the first version hadn’t really been designed carefully. It just happened. Originally it was just a little experiment. Granted, it works fine, but it’s difficult to add new features to it. The second version is a complete re-write designed for the future. AngularFaces 2.0 has a lot of advantages over it’s predecessor.

And the nice thing about AngularFaces 2.0 is it’s already available as a preview version on GitHub.

Update Sept 16, 2014
Actually, the final version of AngularFaces 2.0 looks completely different from the AngularFaces 2.0 I envisioned four months ago. It doesn’t define components, it’s a plugin to existing components. In other words, it adds functionality to most components of Mojarra, MyFaces, PrimeFaces and probably (although I haven’t run a test yet) to most other JSF widget libraries. Nonetheless I think the ideas described in this article are good ideas worthy to be implemented. The AngularFaces widgets have moved to a project called AngularFacesWidgets.
Have a look at the tutorial at if you’re interested in AngularFaces 2.0 and above.
Continue reading “AngularFaces 2: Even Better Steroids for JSF” »

Use Exceptions. Use’em Wisely!

The other day I’ve been reviewing another department’s code. Soon I was puzzled by the way they use exceptions. They use them very often and in unexpected ways. I examined a very small module, just a handful of classes, and the vast majority of the classes were exceptions. After a while it crossed my mind they followed an old style that’s come out of fashion for a good reason.

So I decided to write an article on how to use exceptions efficiently. In a way, this is a strange article: it’s a basic topic (actually a topic already covered by many, many other writers), but it’s not the newbies who do it wrong. It’s the old hands who walk into the trap.
Continue reading “Use Exceptions. Use’em Wisely!” »