Book Image

JSF 2.0 Cookbook

By : Anghel Leonard
Book Image

JSF 2.0 Cookbook

By: Anghel Leonard

Overview of this book

<p>JavaServer Faces is a Java-based Web application framework intended to simplify development of user interfaces for Java EE applications. You may already be aware of the laborious search through reference guides and documentation to develop your JSF applications. With the JSF Cookbook, you can find solutions to the most common JSF problems in a quick and easy way.<br /><br />This book will cover all the important aspects involved in developing JSF applications. It provides clear instructions for getting the most out of JSF and offers many exercises to build impressive desktop-style interfaces for your web applications. Develop JSF applications starting with simple recipes and gradually moving on to complex recipes.<br /><br />We discuss all of the fundamental aspects of JSF applications. Once you locate your desired topic, you can try to find a recipe that corresponds to your problem. <br /><br />We start off with the simple concepts of Converters, validators and file management. We then work our way with various resources such as CSS, JavaScript, and images to improve your web applications. You will learn to build simple and complex custom components to suit your needs. Next, you get to exploit AJAX as well as implement internationalization and localization for your JSF applications. We then look into ensuring security for your applications and perform testing of your applications. You also get to learn all about Facelets and explore the newest JSF 2.0 features. Finally you get learn a few integrations such as JSTL with JSF, Spring with JSF, and Hibernate with JSF. All these concepts are presented in the form of easy-to-follow recipes.<br /><br />Each chapter discusses separate types of recipes and they are presented with an increasing level of complexity from simple to advanced. All of these recipes can be used with JSF 1.2 as well.</p>
Table of Contents (19 chapters)
JSF 2.0 Cookbook
Credits
About the Author
About the Reviewer
Preface
Index

Preface

This book will cover all the important aspects involved in developing JSF applications. It provides clear instructions for getting the most out of JSF and offers many exercises to build impressive desktop-style interfaces for your web applications. You will learn to develop JSF applications starting with simple recipes and gradually moving on to complex recipes.

We start off with the simple concepts of converters, validators, and file management. We then work our way through various resources such as CSS, JavaScript, and images to improve your web applications. You will learn to build simple and complex custom components to suit your needs. Next, you get to exploit AJAX as well as implement internationalization and localization for your JSF applications. We then look into ensuring security for your applications and performing testing of your applications. You also get to learn all about Facelets and explore the newest JSF 2.0 features. Finally, you get to learn a few integrations such as JSTL with JSF, Spring with JSF, and Hibernate with JSF. All these concepts are presented in the form of easy-to-follow recipes.

Each chapter discusses separate types of recipes and they are presented with an increasing level of complexity from simple to advanced. All of these recipes can be used with JSF 1.2 as well as JSF 2.0.

What this book covers

Chapter 1, Using Standard and Custom Converters in JSF covers the standard and custom converters in JSF. We start with implicit and explicit conversion examples, then move on to creating and using custom converters, and we end up with client-side converters using MyFaces Trinidad.

Chapter 2, Using Standard and Custom Validators in JSF continues with standard and custom validators. We see how to use a standard validator, how to create and use custom validators, and how to use RichFaces and Apache MyFaces validators. We also present the new JSF 2.0 validators, such as f:validateRegex and f:validateRequired.

Chapter 3, File Management discusses file management issues. You will see different methods for downloading and uploading files, learn how to use JSF Core, RichFaces, PrimeFaces, and Apache Tomahawk. In addition, you will see how to export data to PDF and Excel, and how to extract data from an uploaded CSV file.

Chapter 4, Security covers some security issues. You will see how to use the JSF Security project without JAAS Roles, use secured managed beans with JSF Security, and use Acegi/Spring security in JSF applications.

Chapter 5, Custom Components discusses custom components in JSF. You will see how to build different kinds of custom components in JSF 2.0, Archetypes for Maven, JSF and Dojo and more.

Chapter 6, AJAX in JSF starts with the f:ajax tag, continues with Dynamic Faces, RichFaces, ajax4jsf, and ends up with PrimeFaces and learning to write reusable AJAX components.

Chapter 7, Internationalization and Localization covers internationalization and localization. We will see how to load message resource bundles on JSF pages and how to use locales and message resource bundles. We then move on to parameterized messages, learning how to display Arabic, Chinese, Russian, and so on and how to select time zones in JSF 2.0.

Chapter 8, JSF, Images, CSS, and JS discusses JSF with images, CSS, JS, and RSS. We will integrate JS with JSF, pass values between JS and JSF, crop images, work with dynamic images, work with pop-up windows, RSS support, and so on.

Chapter 9, JSF—Managing and Testing starts with Faces Console, and moves on to JSFUnit and JMeter.

Chapter 10, Facelets covers Facelets recipes. You will see how to work with aliasing components, templates, composition components, passing actions, and sub-elements to composition components.

Chapter 11, JSF 2.0 Features presents some of the most relevant JSF 2.0 features, such as annotations, exception handling mechanism, declarative event handling, URLs based on specified navigation outcome, JSF view parameters, JSF 2.0, and navigation cases.

Chapter 12, Mixing JSF with Other Technologies discusses mixing JSF with other important technologies, such as Spring, Seam, JSTL, Hibernate, and EJB (JPA).

Appendix, Configuring JSF-related Technologies talks about the issues when a JSF-related technology gets into the equation. You need to add some specific configuration, you have to create a "bridge" between JSF and the technology used. This appendix contains the configurations for a few technologies.

What you need for this book

For performing the recipes from this book you will need the following technologies:

  • JSF 2.0 (or 1.2)

  • NetBeans 6.8

  • GlassFish v3

Also, depending on the recipe, you may also need one of the following technologies:

  • Acegi Spring

  • Apache Maven

  • Apache MyFaces Commons

  • Apache Tomahawk

  • Apache Tomahawk Sandbox

  • Apache Trinidad

  • Dojo

  • Dynamic Faces

  • j4j

  • JSF ID Generator

  • JSF Security

  • JSFUnit

  • Mojarra Scales

  • Pretty Faces

  • PrimeFaces

  • RichFaces

  • rss4jsf

Who this book is for

This book is for two types of audience:

  • Newcomers who know the basics of JSF but are yet to develop real JSF applications

  • JSF developers who have previous experience but are lacking best practices and a standard way of implementing functionality

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Validation can be performed only on UIInput components or components whose classes extend UIInput."

A block of code is set as follows:

</h:inputText>
  <h:message showSummary="true" showDetail="false" for="userNameID" 
             style="color: red; text-decoration:overline"/>
  <br />

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<h:inputText id="userNameID" required="true" 
             value="#{userBean.firstName}">
  <f:validateLength minimum="5" maximum="25" />
</h:inputText> 

Any command-line input or output is written as follows:

SET PATH = "C:\Packt\JSFKit\apache-maven-2.2.1\bin"

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "When you get the BUILD SUCCESSFUL message, you should find a JAR file".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for the book

Visit https://www.packtpub.com//sites/default/files/downloads/9522_Code.zip to directly download the example code.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.