To add the Focus component to the page, use the <o:focus> tag. When this component is added, focus is saved automatically. It is important that all HTML and JSF tags have their ids specified to store focus between submissions by using the Focus component.
The Focus component has a boolean autoSaveFocus attribute. By default, it is set to "true", which means that focus is saved between page submissions.
<h:form> <o:focus autoSaveFocus="true"/> </h:form>
You can specify what component should be focused when the page is loaded using the focusedComponentId attribute. In this attribute, you should specify the id of the component to be focused. Note that the Focus component tracks input focus not just for JSF components but for any HTML input elements as well, so as an alternative you can specify id of an HTML element in the focusedComponentId attribute. It is possible to declare the focusedComponentId attribute as a value expression for loading/saving the focused component through a backing bean.
The focusedComponentId attribute should be defined in the same way as the for property of the standard HTMLOutputLabel component, and as an addition allows referring HTML elements:
<h:form id="form1"> <o:focus focusedComponentId=":input"/> ... <input id="input" type="text"/> </h:form>
If the autoSaveFocus attribute is set to "true", the id of the focused component is saved into the focusedComponentId attribute between page submissions.
You can also specify the org.openfaces.autoSaveFocus context attribute in web.xml to "true" (the default is "false"). This attribute causes focus to be saved between form submissions for all application pages.
<context-param> <param-name>org.openfaces.autoSaveFocus</param-name> <param-value>true</param-value> </context-param>
|© 2010 TeamDev Ltd.|