Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is purpose of label attribute in JSF commandbutton?

Tags:

jsf

What is the purpose of the label attribute in a JSF Command button?

like image 488
BestPractices Avatar asked Mar 28 '12 16:03

BestPractices


1 Answers

Very well spotted. It has really no meaningful purpose on a <h:commandButton>.

This attribute is supposed to be present in UIInput components such as <h:inputText> only. It's then exactly that value which will then be used in the first message format placeholder {0} of validation/conversion messages so that it shows up like so with e.g. label="Username":

Username: Value is required

If the label attribute is omitted, it would default to the component's client ID which is often less friendly readable towards the enduser with autogenerated IDs and : separator and so on like so

formId:inputId: Value is required

This attribute was introduced in JSF 1.2. I think that the mistake of the JSF developer/implementer was to specify the new attrubute for JSF components which generate HTML <input>, <select> and <textarea> elements, not specifically on JSF compnents which extend from UIInput. This attribute is namely (correctly) absent on <h:commandLink> which belongs to the same UICommand family as <h:commandButton>.

I've reported it as issue 2365.

like image 155
BalusC Avatar answered Sep 28 '22 03:09

BalusC