Validating a field using the Hibernate Validator (3.1.0.GA)

How do we apply cross-field validation using the hibernate 3.1.0.GA validator

create a user table (id, start_date, end_date, ...) for example, graduation from college for a student must be more than the end date of training.

How do we ensure this so that validation messages can be displayed in the user interface when performing save and update operations. User interface built using JSF, Richfaces

+3
source share
4 answers

You do this by creating a custom validator. There is more information in the documentation .

+2

:

public class User {

  private Date startDate = null;
  private Date endDate = null;

  @SuppressWarnings("unused")
  @AssertTrue(message="college graduation finishing date for a student should be greater than the graduation start date")
  private boolean dateValidation() {
    return this.startDate < this.endDate;
  }
}
0

See my duplicate question (and answer) in Validating a field in a field using the Hibernate Validator (JSR 303)

In short, create a personalized custom validation level that associates the ConstraintViolation class of the class with validated fields.

0
source

for this approach

@SuppressWarnings("unused")

@AssertTrue(message="college graduation finishing date for a student should be greater than the graduation start date") private boolean dateValidation() { return this.startDate < this.endDate; }

it must conform to the standard bean specification, which means either the get / set / or "is" prefix. isDateValid () will work -

0
source

Source: https://habr.com/ru/post/1728660/


All Articles