Java Reference
In-Depth Information
boolean result = idValue.matches("[0-9]{7}[JJ]");
if (!result) {
FacesMessage message = new FacesMessage();
.substring(component.getClientId().indexOf(":") + 1) +
" issue, please use the format XXXXXXXJJ");
context.addMessage(component.getClientId(), message);
// Set the component's valid attribute to false
((UIInput) component).setValid(false);
If the values passed into the validateUserId method do not match the regular expression pattern, then the
validation fails, and a message is displayed to the user. Now, let's take a look at bean validation to see how it differs from
the use of a JSF validator. Rather than implementing a separate validation method or class, an annotation is placed on
the property field of the bean that you want to validate. The following entity, org.javaee7.entity.Users , contains
bean validation constraint annotations on its fields. The same validation that is being utilized by the validateUserId
method in the previous code listing can be achieved using an @Pattern annotation.
public class Users implements Serializable {
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private BigDecimal id;
private String userId;
@Size(min=8, groups=Authentication.class)
private String username;
@Size(min=8, groups=Authentication.class)
private String password;
private String firstname;
private String lastname;
private String email;
Search WWH ::

Custom Search