Java Reference
In-Depth Information
System.out.println("Calss
:"+cons.getRootBeanClass()+",Instance :
"+cons.getLeafBean()+", "
+ " attribute :
"+cons.getPropertyPath()+",message
:"+cons.getMessage());
}
}
As we mentioned, the Bean Validation Specification can be combined with other spe-
cifications. In the example that follows, we present the coupling between Bean Val-
idation and JSF. We take this opportunity to highlight automatic validation. The ex-
ample that follows demonstrates how to validate the input of a student in our online
preregistration website:
@ManagedBean
public class InscriptionBean {
@Size(min=4, message="The full name must have
"+ " at least four characters!")
private String name;
@Past
private Date birthday;
@NotNull
@Size(min=1, max=1,message="Enter only one
character")
private String gender;
@Pattern(regexp="^\\(?(\\d{3})\\)?[-
]?(\\d{3})[- ]?(\\d{4})$",
message="Invalid phone format, should be as
xxx-xxx-xxxx")
@Size(max = 10)
private String phone;
@Pattern(regexp="[a-z0-9!#$%&'*+/
=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)"
+
"*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
message="Invalid email")
Search WWH ::




Custom Search