Is it best to NOT label a form component (or any other component for that matter) unless you have a need to do so e.g. if you want to be able to reliably distinguish one component from another?
When I see examples of reference components I am always seeing them with a preceding colon e.g. “:dialog” rather than “dialog” or “form:dialog”. Is not naming the form and then specifying the component using a preceding colon the best practice?
If you don’t specify the
idof the form because you don’t need to reference it by a client ID right now, then it will technically not harm to omit it, because JSF will autogenerate one in any way.From inside an ID-less form, for example, you can always reference the parent form as
@forminexecuteandrenderattributes of<f:ajax>to signal that you want to submit and/or render the entire parent form.But if you need to reference for example another form or one of its child components on ajax render, then you should give that form a fixed ID, so that you will be able to reference it by client ID.
Another reason which we’re experiencing in real world projects is that automated web unit testing software such as Selenium really requires a form with a fixed ID, because it needs to find the input fields and submit buttons by their
nameattribute which is also composed based on the JSF form ID. If the JSF form ID is not specified, then the input field name is unpredictable on every deploy/request and thus untestable.All with all, the “best practice” is basically: “only if you need it”. I myself am just getting used to always specify the ID of
NamingContainer,UIInputandUICommandcomponents. “You never know”.