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

Extending CSV with JSF


The Client Side Validation API makes it possible to write our own validators and converters. The writing process is straightforward.

In this recipe, we will develop a custom JSF validator that validates any Unicode strings. The validator will check whether an input value consists of letters, spaces, hyphens, and apostrophes. Any other characters are not allowed. This is a common requirement for validating names of persons, addresses, and similar inputs. We will use the CSV API to implement both server-side and client-side validators. After that, we will see validation in action.

How to do it…

A custom JSF validator must implement two interfaces: javax.faces.validator.Validator and org.primefaces.validate.ClientValidator. The first interface defines a well-known validate() method, and the second one defines the getMetadata() and getValidatorId() methods. Implementing the getMetadata() method should provide optional metadata. Implementing the getValidatorId() method should...