Showing posts from March 22, 2012

Automatically setting the label of a component in JSF 2

In JSF input components have a label attribute that is typically used in (error) messages to let the user know about which component a message is. E.g. Name: a value is required here. If the label attribute isn't used, JSF will show a generated Id instead that is nearly always completely incomprehensible to users. So, this label is something you definitely want to use. Of course, if the label is going to be used in the error message to identify said component, it should also be rendered on screen somewhere so the user knows which component has that label. For this JSF has the separate <h:outputLabel> component, which is typically but not necessarily placed right before the input component it labels. The problem The thing is though that this label component should nearly always have the exact same value as the label attribute of the component it labels, e.g. <h:outputLabel for="username" value="Username" /> <h:inputText id="user