JSF 2.0, Bean Validation and labels

て烟熏妆下的殇ゞ 提交于 2019-12-12 17:33:10

问题


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.


回答1:


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:

javax.faces.validator.BeanValidator.MESSAGE={1}: {0}

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.



来源:https://stackoverflow.com/questions/6803536/jsf-2-0-bean-validation-and-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!