Search in sources :

Example 6 with ValidatorException

use of javax.faces.validator.ValidatorException in project rubia-forums by flashboss.

the class PollValidator method throwValidationException.

private void throwValidationException(String exceptionMsg) throws ValidatorException {
    FacesMessage message = new FacesMessage();
    message.setDetail(getBundleMessage(BUNDLE_NAME, exceptionMsg));
    message.setSummary(getBundleMessage(BUNDLE_NAME, exceptionMsg));
    message.setSeverity(FacesMessage.SEVERITY_ERROR);
    throw new ValidatorException(message);
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 7 with ValidatorException

use of javax.faces.validator.ValidatorException in project oxTrust by GluuFederation.

the class UpdatePersonAction method validateConfirmPassword.

public void validateConfirmPassword(FacesContext context, UIComponent comp, Object value) {
    Pattern pattern = null;
    String attributeValue = (String) value;
    if (StringHelper.isEmpty(attributeValue)) {
        FacesMessage message = new FacesMessage("Value is required");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
    AttributeValidation validation = attributeService.getAttributeByName("userPassword").getAttributeValidation();
    boolean canValidate = validation != null && validation.getRegexp() != null && !validation.getRegexp().isEmpty();
    if (comp.getClientId().endsWith("custpasswordId")) {
        this.password = (String) value;
    } else if (comp.getClientId().endsWith("custconfirmpasswordId")) {
        this.confirmPassword = (String) value;
    }
    if (canValidate) {
        pattern = Pattern.compile(validation.getRegexp());
    }
    if (!StringHelper.equalsIgnoreCase(password, confirmPassword) && this.confirmPassword != null) {
        ((UIInput) comp).setValid(false);
        FacesMessage message = new FacesMessage("Both passwords should be the same!");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
    if (canValidate && (!pattern.matcher(this.password).matches() || !pattern.matcher(this.confirmPassword).matches())) {
        ((UIInput) comp).setValid(false);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, facesMessages.evalResourceAsString("#{msgs['password.validation.invalid']}"), facesMessages.evalResourceAsString("#{msgs['password.validation.invalid']}"));
        context.addMessage(comp.getClientId(context), message);
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation) Pattern(java.util.regex.Pattern) ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage) UIInput(javax.faces.component.UIInput)

Example 8 with ValidatorException

use of javax.faces.validator.ValidatorException in project oxTrust by GluuFederation.

the class GluuAttributeValidator method validate.

@Override
public void validate(FacesContext context, UIComponent comp, Object value) {
    String attributeValue;
    if (value instanceof AttributeDataType) {
        attributeValue = ((AttributeDataType) value).getValue();
    } else {
        attributeValue = (String) value;
    }
    if (StringHelper.isEmpty(attributeValue)) {
        FacesMessage message = new FacesMessage("Value is required");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}
Also used : AttributeDataType(org.gluu.model.attribute.AttributeDataType) ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 9 with ValidatorException

use of javax.faces.validator.ValidatorException in project acs-community-packaging by Alfresco.

the class LoginBean method validatePassword.

/**
 * Validate password field data is acceptable
 */
public void validatePassword(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    int minPasswordLength = Application.getClientConfig(context).getMinPasswordLength();
    int maxPasswordLength = Application.getClientConfig(context).getMaxPasswordLength();
    String pass = (String) value;
    if (pass.length() < minPasswordLength || pass.length() > maxPasswordLength) {
        String err = MessageFormat.format(Application.getMessage(context, MSG_PASSWORD_LENGTH), new Object[] { minPasswordLength, maxPasswordLength });
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 10 with ValidatorException

use of javax.faces.validator.ValidatorException in project acs-community-packaging by Alfresco.

the class LoginBean method validateUsername.

/**
 * Validate Username field data is acceptable
 */
public void validateUsername(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    int minUsernameLength = Application.getClientConfig(context).getMinUsernameLength();
    String name = ((String) value).trim();
    if (name.length() < minUsernameLength || name.length() > 256) {
        String err = MessageFormat.format(Application.getMessage(context, MSG_USERNAME_LENGTH), new Object[] { minUsernameLength, 256 });
        throw new ValidatorException(new FacesMessage(err));
    }
    if (name.indexOf('"') != -1) {
        String err = MessageFormat.format(Application.getMessage(context, MSG_USER_ERR), new Object[] { "\"" });
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) 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