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

Clever focus management in forms


Focus is a component that makes it easy to manage the focus setting on a JSF page. By default, the focus component finds the first enabled (editable) and visible input component on the page and applies focus. Typically, input components are associated with HTML elements, such as input, textarea, and select.

In this recipe, we will learn about the default and advanced behaviors of the Focus component. We will develop two h:panelGrid components with several input components in order to demonstrate the behavior of p:focus in detail.

How to do it…

The XHTML code snippet contains a total of three p:inputText components:

<p:messages/>

<p:focus context="secondGrid"/>

<h:panelGrid columns="2" style="margin-bottom:10px;">
  <h:outputLabel value="Dummy"/>
  <p:inputText/>
</h:panelGrid>

<h:panelGrid id="secondGrid" columns="2">
  <h:outputLabel for="firstname" value="Firstname *"/>
  <p:inputText id="firstname" required...