JSF 2.0 : How to set order of validation error

眉间皱痕 提交于 2019-12-08 01:40:56

问题


I am using Jsf 2 with Hibernate Validator. It works fine, but I don't know how I can set the order of the generated errors.

For an example:

My Managed Bean

public class UserPresentation {

@NotNull(message = "EmailNullError")
@Email(message="EmailNotValidError")
String email;

@NotNull(message="passwordNullError")
String password;
//getter,setter...
} 

In the frontend the passwordNullError appears before the emailNullerror in the generated ul-Tag. How can I change that?


回答1:


You could bind the message labels to your inputs, using the for attribute. The validation messages will appear right behind the according inputs.

<h:inputText value="#{myBean.email}" id="email" />
<h:message for="email" />           
<h:inputSecret value="#{myBean.password}" id="password" />
<h:message for="password" />


来源:https://stackoverflow.com/questions/11139588/jsf-2-0-how-to-set-order-of-validation-error

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