问题
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