I'm familiar with using Spring's <form:errors> tags to display validation errors for object properties, but how do you display an error at the class level?
Here's an example of what I'm talking about:
@ScriptAssert(lang = "javascript",
script = "_this.isExistingEmployee == true || (_this.phoneNumber != null && _this.address != null)",
message = "New hires must enter contact information")
public class JobApplicationForm {
@NotBlank(message = "First Name is required")
private String firstName;
@NotBlank(message = "Last Name is required")
private String lastName;
@NotNull(message = "Please specify whether you are an existing employee in another area")
private Boolean isExistingEmployee;
private String phoneNumber;
private String address;
}
@ScriptAssert here just confirms that if the applicant has indicated that they are an existing employee they can skip the contact info, but if not they must enter it. When this validation fails, the error is not on a given field but rather is on the class.
Within the form, I can show an error on a field with <form:errors path="firstName"> and I can display all errors (class and field) at once using <form:errors path="*"> but how can I isolate and display class level errors?