I am using SpringMVC in my webapp to handle forms and their validation.
In my Validator I have code like this:
@Override
public void validate(final Object target, final Errors errors)
{
final LoginCommand loginCommand = (LoginCommand) target;
if (checkCredentials(loginCommand.getLogin(), loginCommand.getPassword()) {
errors.rejectValue("login", "login.error.invalid");
errors.rejectValue("password", "login.error.invalid");
}
//..
This way I get the properly rendered invalid whenn filling the cssErrorClass attribute. Problem now is that the login.error.invalid message is in the error-message list I am going to display twice.
What is the best way to mark two input fields invalid, but only have one message in the error list? I searched the SpringMVC documentation/api all over and did not find a way to reject a field without supplying a message.
I suggest to mark all form as invalid in this case:
if (checkCredentials(loginCommand.getLogin(), loginCommand.getPassword()) {
errors.rejectValue("login.error.invalid");
}
And show it on view by
<form:errors />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With