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 AngularFaces.com. 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.

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 0×41. 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:metadata>
        <f:viewParam name="keyword" value="#{catalogController.keyword}"/>
        <f:event type="preRenderView" listener="#{catalogController.doSearch}"/>
  </f:metadata>

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();
  work();
  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 BeyondJava.net. 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 beyondjava.net, 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.
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!” »

Tweaking the Hot Spot Compiler’s Settings

A couple of days ago Chris Newland published two interesting articles. He’s looking at the JVM’s Hot Spot compiler settings, looking for possible optimizations.

Regular readers of my blog may remember I analyzed the JVM optimizations two years ago. At the time I found out you can help the optimizing compiler to get to speed, but it doesn’t matter on the long run. After 10.000 invocations methods are compiled to machine code, and after that there’s nothing left to optimize. However, if you happen to work on one of the vast number of algorithms that call methods frequently, but less than – say – 1.000 times, low-level optimizations may help.
Continue reading “Tweaking the Hot Spot Compiler’s Settings” »

AngularFaces Mentioned by Oracle’s Aquarium

It’s astonishing how much attention BeyondJava’s AngularFaces project gets. It has been mentioned in the November issue of the JSF central postcast – at a time when AngularFaces was a far cry from being mature. Last Thursday Reza Rahman mentioned AngularFaces in Oracle’s Aquarium (JSF + AngularJS = AngularFaces?).

I’m very pleased by your tremendous feedback. It’s a great motivation to carry on.

Just in case anyone of you is puzzled by the apparent lack of progress in the repository: progress is there, it just happens in another repository. When I wrote BabbageFaces – which basically was meant to be a small exercise – I noticed many folks in the JSF community want to reduce network traffic. BabbageFaces is nice, but it isn’t compatible to AngularFaces, and it won’t be.

So I decided to tackle the challenge from another angle.
Continue reading “AngularFaces Mentioned by Oracle’s Aquarium” »

How to Display PDF Files in the Browser

PDF files are very popular in web applications. They make it possible to deliver documents that can’t be easily tampered, and you know in advance how PDF documents look like when printed. That’s a major advantage over HTML page: printing an HTML page will almost invariably result in surprises. In many cases cross-browser compatibility – which is always a challenge – comes to a screeching halt when it comes to printing the page. You can avoid a lot of headache by simply using PDF files.
Continue reading “How to Display PDF Files in the Browser” »

Recent Improvements of Java’s String Implementation

Three days ago, I wrote an article about Strings in Java 8. I claimed they’d rewritten java.lang.String from scratch, supporting a 64 bit encoding that can be processed by the processor’s FPU. Of course, it was an April prank. So I was pretty surprised to learn there really are improvements of Java’s string implementation. They aren’t even subtle.

Java 7 Update 6 introduced a new implementation of java.lang.String that’s better suited for large numbers of Strings. As you may or may not know, the former implementation had been designed with optimizing the substring() method in mind. It was super-fast because it didn’t copy the characters of the substring. Instead it created a new pointer to the old String. Sometimes this prevents effective garbage collection, and it makes the intern() function extremely expensive.

So they opted to implement a new version that’s simpler. As a result of the new implementation substring() has to copy the character array. In the age of multi-gigabyte PCs and servers that’s more efficient than trying to save a few bytes.

In Java 7 they also abandoned 8-bit Strings. Now 16-bit Unicode strings are always used. That’s funny because it almost matches my April prank, where I claimed they abandoned the 16-bit character encoding in favor of 64-bit encoding. I wonder if java.lang.String makes use of the FPU?

Read the full story at Attila Balazs article on the state of strings in Java.