How can I show the field label in a JSF error message when bean validation is used?
<h:messages/>
<h:inputText label="Username" value="#{myBean.username}" />
...
public class MyBean {
@NotNull
private String username;
...
}
If no user name is submitted only “Must not be null” is shown and there is no field reference.
To display the concerned component’s label in the error message define a new value for the property javax.faces.validator.BeanValidator.MESSAGE in a resource bundle of the application like this:
The placeholder
{0}refers to the error message as created by the Bean Validation runtime,{1}refers to the component label. More information can be found in the JSF 2 spec. section 3.5.6.3.