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