Focus (<b:focus />)

<b:focus> allows you to define the field that gets the input focus when the page is loaded.

Basic usage

Simply add <b:focus target="someId" > somewhere in your JSF page. The input field bearing this id gets the input focus. The attribute target may also contain a search expression, as long as it results in a unique id.

Some input fields allow you to activate the focus even simpler, by putting <b:focus> inside the input field:

In this example, the focus doesn't seem to work for two reasons: there's a second demo below, which overrides the focus of the first demo, and after that you've clicked the tab, which focuses the tab instead of the input field. However, in a simple form <b:focus /> works as described.

Search expressions

<b:focus /> also works with search expressions. This may allow you to get rid of the ids.

Attribute Default value Description
id (none) Unique identifier of the component in a namingContainer.
rendered false Boolean value to specify the rendering of the component, when set to false the component will not be rendered.
target (none) Id of the element to focus. May be omitted if you put the b:focus element inside the element.