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);
}
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);
}
}
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);
}
}
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));
}
}
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));
}
}
Aggregations