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 with several input components in order to demonstrate behavior of p:focus in detail.

How to do it...

The default behavior of the Focus component can be restricted by the context attribute. Although we have two h:panelGrid components, only the second will be considered for p:focus.

<p:messages/> ...

Get PrimeFaces Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.