servlets struts hibernate spring maven java
 

JSF Bean Validation



JSF gives approval requirements to bean model as comments. You can put that explanations on a field, method, or class of a JavaBeans componet, for example, an oversaw bean.

JSF additionally gives office to make custom or client characterized requirements. The inherent limitations are accessible in the javax.validation.constraints bundle and postponed in the accompanying table.

Constraint Description Example
@NotNull It is used to set not null constraint to the value of the field or property. @NotNull String username;
@Null It is used set null constraint to the value of the field or property. @Null String unusedString;
@Size It is used to specify size of field or property. The size of the field or property is evaluated and must match the specified boundaries. Use one of the optional max or min elements to specify the boundaries. @Size(min=2, max=240) String briefMessage;
@Digits It is used to set constraint that the value of the field or property must be a number within a specified range. The integer element specifies the maximum integral digits for the number, and the fraction element specifies the maximum fractional digits for the number. @Digits(integer=6, fraction=2) BigDecimal price;
@DecimalMin This constraint specifies that the value of the field or property must be a decimal value greater than or equal to the number in the value element. @DecimalMin("5.00") BigDecimal discount;
@DecimalMax It is used to specify that the value of the field or property must be a decimal value lower than or equal to the number in the value element. @DecimalMax("30.00") BigDecimal discount;
@Max It is used to set the value of the field or property which must be an integer value lower than or equal to the number in the value element. @Max(10) int quantity;
@Min It is used to set the value of the field or property which must be an integer value greater than or equal to the number in the value element. @Min(5) int quantity;
@Pattern It is used to set patter which must match the regular expression defined in the regexp element. @Pattern(regexp="\\(\\d{3}\\)\\d{3}-\\d{4}") String phoneNumber;
@Past It is used to set the value of the field or property which must be a date in the past. @Past Date birthday;
@Future It is used to set the value of the field or property which must be a date in the future. @Future Date eventDate;
@AssertTrue It is used to set the value of the field or property which must be true. @AssertTrue boolean isActive;
@AssertFalse It is used to set the value of the field or property which must be false. @AssertFalse boolean isUnsupported;






© Javacodegeeks © 2019 - 2019
All Right Reserved and you agree to have read and accepted our term and condition.

Python 3