Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

PrimeFaces Cookbook, Second Edition, is the most comprehensive book about PrimeFaces—the rapidly evolving and leading JSF component suite. The book provides a head start to its readers by covering all the knowledge needed to work with the PrimeFaces framework and components in the real world. It is a quick, practical guide to learn PrimeFaces, written in a clear, comprehensible style. PrimeFaces Cookbook, Second Edition, addresses a wide audience interested in modern, trendsetting Java EE web development.

What this book covers

Chapter 1, Getting Started with PrimeFaces, provides details on the setup and configuration of PrimeFaces, along with the core concepts for every web application powered by PrimeFaces. The chapter gives a sneak preview of the basic features of PrimeFaces, such as AJAX processing and updating, component referencing by keywords and selectors, partial submitting, handling with Internationalization and Localization, along with the right-to-left language support and resource ordering.

Chapter 2, Theming Concepts, introduces PrimeFaces themes and the concept involved. Readers will learn about the theming of PrimeFaces components. The difference between structural and skinning CSS, installing and customizing PrimeFaces themes, along with creating new themes, will be detailed. Readers will also see how to adjust the font family and the font size throughout the PrimeFaces components to provide a consistent look and feel. Discussions of two variants of theme switchers and integrating additional icons finish this chapter.

Chapter 3, Enhanced Inputs and Selects, explains how to work with the input and select components available in PrimeFaces. Such components are the main parts of every web application. PrimeFaces provides nearly 25 components for data input that extend the standard JSF component suite with user-friendly interfaces, skinning capabilities, AJAX interactions, Client-side Validation, and many other useful features.

Chapter 4, Grouping Content with Panels, covers various container components, such as panel, accordion, scrollPanel, tabView, and dashboard, which allow grouping of JSF components. Various settings to configure panel components are detailed in this chapter. Furthermore, the chapter explains how to create complex layouts with the layout component and also responsive layouts for mobile devices and desktops with Grid CSS.

Chapter 5, Data Iteration Components, covers basic and advanced features to visualize data with data iteration components provided by PrimeFaces, including dataTable, dataList, pickList, orderList, tree, and treeTable. The discussed features include sorting, pagination, filtering, lazy loading, and single and multiple selections. Advanced data visualization with the schedule and dataScroller components will be demonstrated as well.

Chapter 6, Endless Menu Variations, explains several menu variations. PrimeFaces' menus fulfill all major requirements. They come with various facets—static, dynamic, tiered, hybrid, iPod-styled, and so on—and leave nothing to be desired. Readers will face a lot of recipes that discuss the menu's structure, configuration options, customizations, and integration with other components. At the end of this chapter, readers will know what kind of menu to choose and how to put it on a page for a particular use case.

Chapter 7, Working with Files, Images, and Multimedia, provides ways of managing operations on files such as uploading and downloading, image operations such as capturing, cropping, and displaying images with galleria, imageSwitch, and contentFlow. Readers will learn basic as well as advanced configuration of components and use cases.

Chapter 8, Drag Me, Drop Me, explains how the drag and drop utilities in PrimeFaces allow you to create draggable and droppable user interfaces efficiently. They abstract developers from dealing with implementation details on the browser level. In this chapter, readers will learn about PrimeFaces' drag and drop utilities—Draggable and Droppable. AJAX-enhanced drag and drop and a special integration with data iteration components will be explained as well.

Chapter 9, Creating Charts and Maps, covers the ways to create visual charts with PrimeFaces' extensive charting features and create maps based on Google Maps. PrimeFaces offers basic and advanced charting with its easy-to-use and user-friendly charting infrastructure. Throughout the chapter, mapping abilities such as drawing polylines and polygons and handling markers and events are covered as well.

Chapter 10, Client-side Validation, gives advice on how to implement Client-side Validation (CSV) with PrimeFaces. PrimeFaces' Client Side Validation Framework is the most complete and advanced CSV solution for JSF. Readers will learn all CSV tricks—configuration, standard validation, instant validation, and integration with Bean Validation. They will also meet custom client-side validators and find out how to extend CSV with JSF validators and Bean Validation.

Chapter 11, Miscellaneous Advanced Use Cases, introduces more interesting features of the PrimeFaces library. You will learn about RequestContext—a helpful utility that allows marking components as updatable targets at runtime, adding AJAX callback parameters, opening external pages in dynamically generated dialog (Dialog Framework), and more. In this chapter, a number of real-world samples will be also developed—blocking UI during AJAX calls, periodic polling, focus handling, controlling from submission, sticking components, content caching, and targetable messages, to name a few. Furthermore, after reading this chapter, readers will be aware of the pitfalls of menus within layout units and nested panels as well as possibilities for exception handling.

What you need for this book

The PrimeFaces core functionality only requires a Java 5+ runtime. The PrimeFaces library is just one single JAR file. With the help of the Maven tool, you can easily get the artifact for the PrimeFaces library (for more information on installing Maven, visit http://maven.apache.org). Please note that Maven demands a Java Development Kit installed on your local environment instead of on the Java Runtime Environment. Alternatively, you can download the JAR directly from the Maven central repository (http://search.maven.org) and add it to the project's classpath.

The showcase to PrimeFaces Cookbook, Second Edition, is hosted on GitHub at https://github.com/ova2/primefaces-cookbook/tree/second-edition. The homepage on GitHub contains all the details on how to clone the Git repository with the source code and build and run the showcase web application in your local environment.

Who this book is for

This book is for everybody who would like to learn modern Java web development based on PrimeFaces and is looking for a quick introduction to this matter. Prerequisites for this book are basic JSF, jQuery, and CSS skills.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

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

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

<repository>
  <id>prime-repo</id>
  <name>PrimeFaces Maven Repository</name>
  <url>http://repository.primefaces.org</url>
</repository>

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

Data:javax.faces.partial.ajax=true&javax.faces.source=j_idt19&jav
ax.faces.partial.execute=name&j_idt19=j_idt19&mainForm=mainForm&bo
okTree_selection=0_6&name=mert&j_idt21=&j_idt22=&j_idt23=&j_id
t24=&j_idt25=&j_idt26=&j_idt27=&j_idt28=&j_idt29=&javax.fac
es.ViewState=-6151865609302284540%3A502720797990996178

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "When the button with the Partial Submit (False) label is clicked, the AJAX request that will be sent to the server will contain all the ID's of the input text fields that exist on the page."

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at 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.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/3427OS_Graphics.pdf.

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 could 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/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.