Bean Validation

  • Część platformy JEE odpowiedzialna za walidację Java Bean
  • Jeden standard (API) do walidacji oraz podstawowe mechanizmy to umożliwiające (tzw. walidatory)
  • Możliwość tworzenia własnych walidatorów (lub wykorzystywania zewnętrznych bibliotek jak Hibernate Validators)

Specyfikacje

  • JSR 303 - specyfikacja Java API dla JEE oraz JSE do walidacji Java Beans. Określa, że właściwość (property) beanu musi spełniać określone kryteria wyspecyfikowane za pomocą annotacji takich jak @NotNull czy też @Min, @Max etc
  • JSR 349 - rozszerzenie JSR 303 o takie funkcjonalności jak „dynamic expression evaluation” w wiadomościach, interpolacja wiadomości i wiele innych

Wbudowane walidatory

  • @AssertFalse - The value of the field or property must be false
  • @AssertTrue - The value of the field or property must be true
  • @NotNull - The value of the field or property must not be null
  • @Null - The value of the field or property must be null
  • @Pattern - The value of the field or property must match the regular expression defined in the regexp element
  • @Max - The value of the field or property must be an integer value lower than or equal to the number in the value element
  • @Min - The value of the field or property must be an integer value greater than or equal to the number in the value element
  • @Size - The size of the field or property is evaluated and must match the specified boundaries
  • @DecimalMax - The value of the field or property must be a decimal value lower than or equal to the number in the value element
  • @DecimalMin - The value of the field or property must be a decimal value greater than or equal to the number in the value element
  • @Digits - The value of the field or property must be a number within a specified range
  • @Future - The value of the field or property must be a date in the future
  • @Past - The value of the field or property must be a date in the past

Zadanie

  1. Dodać na stronie formularz kontaktowy (z odpowiednim beanem oraz servletem) składający się z:
    • imienia
    • adresu email
    • wiadomości
  2. Dodać walidację formularza

results matching ""

    No results matching ""