20.04.2013 Views

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1 THE BASICS<br />

Validation. It is now possible to perform validation on the client according to JSR-303 definitions. It<br />

means that basic client-side validation no longer requires creating and plugging custom JavaScript<br />

validators to components; it just synchronizes them for different layers at the framework level.<br />

Also, with <strong>RichFaces</strong> you will be able to achieve that validation across the whole application<br />

following the DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principle. In case validating<br />

on the client is not possible, Ajax fallback (server-side) support is available. Besides, <strong>RichFaces</strong> provides<br />

so-called Object Validation that allows validating server-side Entities in the whole, even if some<br />

properties are not present in current view. Client-side validation is covered in Chapter 11.<br />

<strong>RichFaces</strong>’ Component Development Kit<br />

Another part of the framework is the Component Development Kit (CDK). The CDK includes various<br />

Maven archetypes, a code generation facility, descriptors and tests generation facility, and a templating<br />

facility that allows the creation of renderer classes using only page code. These features enable a<br />

component developer to avoid the routine process of component creation. The CDK greatly simplifies<br />

and speeds up rich component development with built-in Ajax support. This edition of the book now<br />

includes CDK coverage. CDK is covered in Chapter 13.<br />

Using <strong>RichFaces</strong> with CDI and Dependency Injection<br />

Contexts and Dependency Injection, or CDI (JSR 299), and Dependency Injection for Java (JSR 330) are<br />

both part of the Java EE 6 platform. Both provide services and components to make it simpler to develop<br />

enterprise Java applications. Although JSF 2 now provides a simpler way to configure beans with<br />

annotations, using CDI beans instead of JSF beans gives a lot more flexibility and power to the developer<br />

by providing a unified programming model. JSF 2 works with CDI Beans out of the box. As <strong>RichFaces</strong> 4 is<br />

based on JSF 2, CDI can be used with any <strong>RichFaces</strong> 4 components as well. So that we don’t introduce<br />

another layer (which is really outside the scope of this book), examples in this book will use standard JSF<br />

beans. In all examples, JSF beans can be easily replaced with CDI beans.<br />

<strong>RichFaces</strong>: A Historical Perspective<br />

If you search for <strong>RichFaces</strong>, eventually you will see a reference to Ajax4jsf. This section provides a brief<br />

history of Ajax4jsf and how it became part of <strong>RichFaces</strong>. Ajax4jsf has its roots in <strong>RichFaces</strong>. The Ajax4jsf<br />

framework was created and designed by Alexander Smirnov. In early 2005, he was looking to add a<br />

“hot” new technology along with the associated experience to his résumé. Roughly at the same time,<br />

Jesse James Garrett was establishing the concept of Ajax. Meanwhile, JSF was starting to pick up steam.<br />

Alexander figured, why not just merge the two so it would be easy to have Ajax functionality within a<br />

JSF application?<br />

He started the project on SourceForge.net, called it Telamon (taken from the Shakespearean play,<br />

Antony and Cleopatra), and Ajax4jsf was born. In the fall of that same year, Smirnov joined Exadel, a<br />

software engineering company, and continued to develop the framework. Smirnov’s goal was to create a<br />

tool that was easy to use, would add client-side richness to pure server-side JSF technology, and could be<br />

used with any existing JSF component libraries.<br />

The first version of what would become Ajax4jsf was released in March 2006. It wasn’t quite a standalone<br />

thing yet. Rather, it was part of a product called Exadel <strong>RichFaces</strong>. Later in the same year,<br />

<strong>RichFaces</strong> was split off, and the Ajax4jsf framework was born.<br />

While <strong>RichFaces</strong> provided out-of-the-box components, or what’s called a component-centric Ajax<br />

approach (components that do everything you need), Ajax4jsf provided what’s called page-wide Ajax<br />

support. You as a developer specify what parts of the page should be processed on the server after clientside<br />

user actions, and also what parts should be rendered back (rendering is happening on the server

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!