Tim Holloway wrote:There is no other way to set focus on a web page than JavaScript. JSF is at the mercy of the limitations of HTML and HTML doesn't have such an option.
The reason that your JavaScript failed is because the IDs and structures of JSF's View Template Language (xhtml) are abstract and don't directly correspond to those in the rendered HTML and JavaScript must operate based on what's in the rendered HTML. Use your browser's "View Page Source" tool to see what actually got rendered and code your JavaScript accordingly. Note that if you do not explicitly code id's on your controls and their "naming containers" (forms, tables and so forth) that JSF with automatically synthesize IDs (j_123) but those IDs are neither constant nor predictable, unlike explicitly-coded IDs. Also that the ID of the rendered HTML is a concatenation of the control's ID plus the IDs of its parent naming containers.
Ok, I already done that and I saw my JS untouched and it should work, see:
As you can see I overrided window.onload event and focused on the element ID "form:usuario", why it isn't working?