Search in sources :

Example 1 with ValidatorException

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

the class LoginBean method validateMatch.

// ------------------------------------------------------------------------------
// Validator methods
/**
 *  Validate that field "confirm" matches to the field "password"
 */
public void validateMatch(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    String confirm = (String) value;
    String field1Id = (String) component.getAttributes().get("passwd1Id");
    UIInput passComponent = (UIInput) context.getViewRoot().findComponent(field1Id);
    String pass = (String) passComponent.getSubmittedValue();
    if (pass == null) {
        pass = (String) passComponent.getValue();
    }
    if (!pass.equals(confirm)) {
        String err = Application.getMessage(context, UsersDialog.ERROR_PASSWORD_MATCH);
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) UIInput(javax.faces.component.UIInput) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with ValidatorException

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

the class CreateUserWizard 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, LoginBean.MSG_USERNAME_LENGTH), new Object[] { minUsernameLength, 256 });
        throw new ValidatorException(new FacesMessage(err));
    }
    if (name.indexOf('"') != -1 || name.indexOf('\\') != -1) {
        String err = MessageFormat.format(Application.getMessage(context, LoginBean.MSG_USER_ERR), new Object[] { "\", \\" });
        throw new ValidatorException(new FacesMessage(err));
    }
    try {
        name = PersonServiceImpl.updateUsernameForTenancy(name, getTenantService());
    } catch (TenantDomainMismatchException e) {
        String err = MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR_DOMAIN_MISMATCH), e.getTenantA(), e.getTenantB());
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) TenantDomainMismatchException(org.alfresco.repo.tenant.TenantDomainMismatchException) FacesMessage(javax.faces.application.FacesMessage)

Example 3 with ValidatorException

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

the class CreateUserWizard method validateEmail.

/**
 * Validate Email field data is acceptable
 *
 * @param context FacesContext
 * @param component UIComponent
 * @param value Object
 * @throws ValidatorException
 */
public void validateEmail(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    String emailRegExp = Application.getClientConfig(context).getEmailRegExp();
    Pattern pattern = Pattern.compile(emailRegExp, Pattern.CASE_INSENSITIVE);
    if (!pattern.matcher((CharSequence) value).matches()) {
        String err = Application.getMessage(context, MSG_ERROR_MAIL_NOT_VALID);
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : Pattern(java.util.regex.Pattern) ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 4 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 5 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)

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