use of javax.faces.validator.ValidatorException in project oxTrust by GluuFederation.
the class PasswordValidator method validate.
@Override
public void validate(FacesContext arg0, UIComponent arg1, Object value) throws ValidatorException {
if (attributeService == null) {
attributeService = CdiUtil.bean(AttributeService.class);
}
GluuAttribute attributeByName = attributeService.getAttributeByName(USER_PASSWORD);
AttributeValidation validation = attributeByName.getAttributeValidation();
if (validation != null && validation.getRegexp() != null && !validation.getRegexp().isEmpty()) {
pattern = Pattern.compile(validation.getRegexp());
hasValidation = true;
}
if (hasValidation) {
matcher = pattern.matcher(value.toString());
}
if (hasValidation && !matcher.matches()) {
FacesMessage msg = new FacesMessage(facesMessages.evalResourceAsString("#{msgs['password.validation.invalid']}"));
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
use of javax.faces.validator.ValidatorException in project oxTrust by GluuFederation.
the class RegisterPersonAction method validateEmail.
public void validateEmail(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String email = (String) value;
if ((email == null) || (email.trim().equals(""))) {
FacesMessage message = new FacesMessage("Please Enter Your Email Address.");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email);
if (!(matcher.matches())) {
FacesMessage message = new FacesMessage("Please Enter Valid Email Address.");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
use of javax.faces.validator.ValidatorException in project survey by markoniemi.
the class EmailValidator method validate.
@Override
public void validate(FacesContext context, UIComponent component, Object value) {
Matcher matcher = PATTERN.matcher(value.toString());
if (!matcher.matches()) {
FacesMessage msg = new FacesMessage("E-mail validation failed.", "Invalid E-mail format.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
use of javax.faces.validator.ValidatorException in project fit3d by fkaiserbio.
the class FileValidator method validate.
@Override
public void validate(FacesContext content, UIComponent component, Object value) throws ValidatorException {
List<FacesMessage> messages = new ArrayList<>();
Part file = (Part) value;
if (file.getSize() > Fit3DWebConstants.MAXIMAL_UPLOAD_SIZE) {
messages.add(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Maximal size exceeded.", "The file you are trying to upload exceeds the maximal allowed size."));
}
if (!"text/plain".equals(file.getContentType())) {
messages.add(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Not a text file.", "The file you are trying to upload is not a plain text file."));
}
if (!messages.isEmpty()) {
throw new ValidatorException(messages);
}
}
Aggregations