HTML and CSS Reference
In-Depth Information
■
Covering the complete features of JSr 303 is outside of the scope of this topic; you can read the complete
Note
All of the validated fields in Listing 3-15 belong to the
Default
validation group of the Java Bean Validation
framework; however, you have the option to specify many validation groups for the same constraint. A validation
group is nothing more than a tag interface. Let's create two validation groups called (
LengthGroup
) and (
EmailGroup
).
LengthGroup
will group the length constraints in
Person
managed bean (
@Size
constraints), while
EmailGroup
will
include the e-mail constraint in
Person
managed bean (
@EmailAddress
constraint). Then attach the validation groups
to the constraints as shown in Listing 3-19.
Listing 3-19.
Validation Groups in Person Managed Bean
@ManagedBean
@RequestScoped
public class Person implements Serializable {
@Size(min = 4, max = 30, groups = LengthGroup.class)
private String name;
@Size(min = 12, max = 120, groups = LengthGroup.class)
private String address;
@Size(min = 5, max = 30, groups = LengthGroup.class)
@EmailAddress(groups = EmailGroup.class)
private String email;
public Person() {
}
public String subscribe() {
return null;
}
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;
}
