Mohit Kanwar
Mohit Kanwar

Reputation: 3050

Spring errors tag, show additional errors

I have a password field defined in JSP

<form:password path="userprofile.password" id="password"  />

form taglib refers to Spring form taglib (http://www.springframework.org/tags/form)

The JSP form contains other fields as well e.g. .

<form:input path="userform.name"  />

Since this is a password, even if user has provided valid password, it disappears on page reload.

Consider this scenario: User has provided a valid password, but there is an error in "Name" field. on submit, page reloads and the error for "Name" is displayed, and password field is emptied out.

I want to show a message to user that the entered password is emptied due to security reasons and the user needs to enter that as well.

However, if the error is in password field itself, this additional message should not be shown.

Please suggest a solution.

PS: I tried the solutions at Spring Forms - How to Check for Error on Specific Path

They work for all fields apart from password, where I want.

Upvotes: 1

Views: 145

Answers (1)

Mohit Kanwar
Mohit Kanwar

Reputation: 3050

I could not find a way to do the same in JSP. However, at spring controller (when the form was submitted) I used the following code to make it work:

if (!errors.hasFieldErrors("password")){
    errors.rejectValue("password", "My Error Message Key....");
}

PS: errors is the instance of org.springframework.validation.Errors which we get from Spring framework.

Upvotes: 0

Related Questions