HTML and CSS Reference
In-Depth Information
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
As shown in the bolded lines, we used the @size built-in Java Bean Validation annotation in order to control the
sizes of name and address fields. The @size annotation has mainly two attributes, min and max , to validate the length
of the annotated fields. @EmailAddress annotation is a custom constraint that we use to validate email attribute of
Person managed bean. Listing 3-16 shows the code of the @EmailAddress annotation.
Listing 3-16. @EmailAddress Annotation
package com.jsfprohtml5.subscriber.bean.validation.custom;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
@Target({ElementType.FIELD, ElementType.METHOD})
@Constraint(validatedBy = EmailValidator.class)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EmailAddress {
String message() default "{email.invalid}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
 
Search WWH ::




Custom Search