Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Working with client behavior functionality


JSF 2 comes with the ability to define specific client-side behavior to a component in a reusable approach. The client-side behavior is actually a piece of JavaScript code that can be executed in a browser.

For example, when the user has access to buttons that perform irreversible changes; for example, deletion, copy, and move is a good practice to inform the user about consequences and ask for a confirmation before the action is performed.

For implementing a client behavior functionality, we perform the following steps:

  1. Extend the ClientBehaviorBase class.

  2. Override the getScript method.

  3. Annotate the created class with the @FacesBehavior (value="developer_id") annotation where developer_id is used to refer to our custom client behavior. This is needed when we define a tag for the behavior.

  4. Define a custom tag for the behavior—a tag is needed for specifying in the JSF pages, which components receive our client behavior (the JS code).

  5. Register the custom...