Search in sources :

Example 21 with ValidatorException

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);
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation) ValidatorException(javax.faces.validator.ValidatorException) AttributeService(org.gluu.oxtrust.service.AttributeService) FacesMessage(javax.faces.application.FacesMessage) GluuAttribute(org.gluu.model.GluuAttribute)

Example 22 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) Matcher(java.util.regex.Matcher) FacesMessage(javax.faces.application.FacesMessage)

Example 23 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) Matcher(java.util.regex.Matcher) FacesMessage(javax.faces.application.FacesMessage)

Example 24 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) Part(javax.servlet.http.Part) ArrayList(java.util.ArrayList) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)24 ValidatorException (javax.faces.validator.ValidatorException)24 UIInput (javax.faces.component.UIInput)5 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AttributeValidation (org.gluu.model.attribute.AttributeValidation)2 Period (com.artezio.arttime.datamodel.Period)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 UIComponent (javax.faces.component.UIComponent)1 FacesContext (javax.faces.context.FacesContext)1 Validator (javax.faces.validator.Validator)1 Part (javax.servlet.http.Part)1 ConstraintViolation (javax.validation.ConstraintViolation)1 TenantDomainMismatchException (org.alfresco.repo.tenant.TenantDomainMismatchException)1 GluuAttribute (org.gluu.model.GluuAttribute)1 AttributeDataType (org.gluu.model.attribute.AttributeDataType)1 AttributeService (org.gluu.oxtrust.service.AttributeService)1