I want to set focus on commandButton field in JSF2(Mojarra) on page load. How can I implement this without using Javascript? Could anyone please help me on this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is only possible when the browser supports HTML5. You can then use the new HTML5
autofocusattribute so that you ultimately end up withThis attribute is not supported by the JSF
<h:commandButton>component. Adding arbitrary attributes to JSF components like<h:commandButton autofocus="true">is also not natively supported by JSF, it would be plain ignored. You’d basically need to create a custom tag/component which supports the new attribute.You can also use a custom
RenderKitto write unsupported attributes anyway. The JSF utility library OmniFaces has since version 1.3 aHtml5RenderKitfor exactly this purpose.Again, this works only in browsers supporting HTML5
autofocusattribute.