Alternatively, focus can be enforced on server-side using FocusManager interface.
In a following example, focus is after each request placed on input2 component, since there is FocusManager call bind to preRenderView listener:
<!DOCTYPE html> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <f:event type="preRenderView" listener="#{focusManagerBean.preRenderView}" /> <rich:panel header="Enforcing Focus of Given Input"> <h:form id="form"> <h:panelGrid columns="2"> input1: <h:inputText id="input1" /> input2: <h:inputText id="input2" /> input3: <h:inputText id="input3" /> </h:panelGrid> <h:commandButton value="Form Submission" /> <a4j:commandButton value="Ajax Request" /> </h:form> </rich:panel> </ui:composition>
package org.richfaces.demo.focus; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import org.richfaces.application.ServiceTracker; import org.richfaces.focus.FocusManager; @RequestScoped @ManagedBean public class FocusManagerBean { public void preRenderView() { FocusManager focusManager = ServiceTracker.getService(FocusManager.class); focusManager.focus("input2"); } }