Skip to main content

PrimeFaces works great with JSF 2.0/NetBeans 6.9

Posted by cayhorstmann on September 13, 2010 at 12:15 AM PDT

In 2002, JSF was introduced at Java One as “Swing for the Web”. The vision was that you would compose professionally designed components into web pages, add a bit of Java glue code, and presto, you would have a web app without having to worry about HTTP or the DOM.

I perked up because I didn't want to worry about HTTP or the DOM. This was before Ajax was invented, and before I knew that I certainly didn't want to know about the XMLHttpRequest object or JSON.

Ever since, I have been fussing with JSF, not always happily. A couple of years, I wrote this blog about a JSF 1.2 project. I liked the Woodstock component set. But I groused about having to redeploy all the time, the stack trace from hell, and the lack of templating.

What a difference two years make. With GlassFish 3 and JSF 2, templating is easy, hot deployment works pretty well, and Facelets error reporting means that the stack trace from hell is much less common. (Now if the rest of Java EE could do as well and give me the source file/line number for each error...I am looking at you, Weld...)

However, as I ported an app to JSF 2, I had to give up on Woodstock. It has been abandoned and does not seem to work with JSF 2. First, my graduate student Ashlesha Patil provided a UI that used just the basic HTML components. It worked fine but looked rather plain.

So, I looked for another component set that was ready for JSF 2 and took advantage of its latest features. The one that seems furthest along is PrimeFaces (version 2.2M1). It is dead simple to use. No more wretched web.xml or faces-config.xml customizations. Simply add the JAR to WEB-INF/lib and add


to each XHTML page. Then you can use goodies such as p:tabView and p:accordion. After an hour of fussing, the screen looks like this:

That's more like it. Clicking on the tabs and accordion buttons gives subtle animation effects, without any work on my part. There are plenty of themes to choose from if blue and gray aren't your thing. And of course, there are lots of components.

NetBeans 6.9 does code completion on the tags and presents the documentation:

NetBeans 6.10 will include PrimeFaces out of the box, so you won't even have to download the JAR.

After all these years, JSF is finally getting pretty close to its original promise. I really like that I can think in terms of components—such as the tab view or accordion component—without having to worry about HTML or JavaScript. And I can let someone else author these components.

The next step on my wish list is a JSF app framework—something that gives me the basic structure that is common to many apps. In particular, I never want to write the code for login and password recovery again.

Related Topics >>


Right you are!

>After all these years, JSF is finally getting pretty close to its original promise. Indeed, I so much agree with this. I remember this original promise very well, although my own memory doesn't go back that far ;) For me some 7 years later, it finally delivers. The existence of rich component libraries that work well together is really a key issue. For a long time, this wasn't really the case, but now it's finally happening!

This is for students like me 6 years ago

In my opinion (based on my experience), the more you know about javascript & html the better you are (unless you work on the server side and db). And for html, try to use div, float ... whenever you can (avoid tables).

The cool thing about JSF is,

The cool thing about JSF is, it offers you an ecosystem with component libraries like PrimeFaces and allows you to create these stuff on your own easily as well. With JSF 2.0's composition component feature, it is a trivial process to create your own rich component with your favorite javascript library. Sure without JSF, with plain html+js you can do the same but with much more effort since JSF also gives you integrated ajax, validations, model update and much more. As for PrimeFaces, we are using jQuery as the client side javascript library as it is a fun library to work with. Also note that, PrimeFaces is not just a wrapper, jQuery UI has 6-7 widgets and PrimeFaces has nearly 100 JSF components, so this means we've also built many of our own widgets ourselves and integrated with ThemeRoller CSS framework for skins. Another example I can give is tabView, jQuery UI gives you a tabview widget, with PrimeFaces you get extra features like ajax tabChangeListener, dynamic tab content loading and more which will require considerable amount of javascript+java code to implement this on your own. JSF 2.0-PrimeFaces allows you to create rich UIs without requiring much effort so developers can focus on business instead of UI, this speeds up development and reduces costs which most companies are looking for in enterprise world.

Why not just use a simple JavaScript library?

Dr. Horstmann, for those vaguely familiar with JavaScript libraries like YUI or Dojo, whipping up a Tabbed layout or AccordionContainer with panes is usually a 5 minute task. All it takes is a couple lines of JavaScript and this allows one to use regular HTML instead of numerous

s. With JavaScript being almost omni-present now, dont you feel its time Java programmers spend a little time understanding how basic UI components can be put together using simple JavaScript and regular HTML?

Nothing wrong with using a

Nothing wrong with using a JavaScript library. That's what PrimeFaces does under the hood. In fact, they switched from YUI to jQuery, and that was apparently pretty transparent to their users.

Should Java programmers *understand* what goes on with that JavaScript? I don't know how much the average YUI or jQuery user understands the JavaScript--if you just give your library a bunch of div and li, together with a few arcane class names and magic JS calls, that doesn't seem to involve much understanding. In that case, why not have that generated by JSF components?

I don't want to deter anyone from learning a JS library--if you use Lift, I am sure it'll save your bacon :-)