diff --git a/1.sources/MyHealth/src/managedbean/validators/EmailValidator.java b/1.sources/MyHealth/src/managedbean/validators/EmailValidator.java index b866476..86b2a9e 100644 --- a/1.sources/MyHealth/src/managedbean/validators/EmailValidator.java +++ b/1.sources/MyHealth/src/managedbean/validators/EmailValidator.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.el.ValueExpression; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; @@ -13,6 +14,8 @@ import javax.faces.validator.ValidatorException; import org.primefaces.validate.ClientValidator; +import managedbean.systemAdmin.AddAdminMBean; + @FacesValidator("emailValidator") public class EmailValidator implements Validator, ClientValidator { @@ -21,16 +24,32 @@ public class EmailValidator implements Validator, ClientValidator { public void validate(FacesContext context, UIComponent comp, String value) throws ValidatorException { String strValue = ""; - + if (value != null) - strValue = String.valueOf(value); - + strValue = String.valueOf(value).toLowerCase(); + if (strValue.equals("")) throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Correo electrónico no válido", "La dirección " + value + " no es una dirección válida")); Matcher matcher = EMAIL_COMPILED_PATTERN.matcher((String) value); if (!matcher.matches()) throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Correo electrónico no válido", "La dirección " + value + " no es una dirección válida")); + + boolean emailIsDupe = false; + ValueExpression valueExpr = comp.getValueExpression("managedBean"); + + if (valueExpr != null) { + Object managedBean = comp.getValueExpression("managedBean").getValue(context.getELContext()); + + if (managedBean instanceof AddAdminMBean) { + AddAdminMBean admBean = AddAdminMBean.class.cast(managedBean); + emailIsDupe = admBean.emailAlreadyRegistered(strValue); + } + } + + if (emailIsDupe == true) + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, "Correo electrónico ya registrado", + "La dirección de correo electrónico " + strValue + " ya ha sido registrada en el sistema")); } public Map getMetadata() { diff --git a/1.sources/MyHealth/src/managedbean/validators/NifValidator.java b/1.sources/MyHealth/src/managedbean/validators/NifValidator.java index 25bd686..4b14373 100644 --- a/1.sources/MyHealth/src/managedbean/validators/NifValidator.java +++ b/1.sources/MyHealth/src/managedbean/validators/NifValidator.java @@ -2,6 +2,7 @@ package managedbean.validators; import java.util.Map; +import javax.el.ValueExpression; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; @@ -32,16 +33,20 @@ public class NifValidator implements Validator, ClientValidator { if (ValidationUtils.isValid(strValue) == false) throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "El NIF no es válido", "El NIF " + strValue + " no es válido")); - - Object managedBean = comp.getValueExpression("managedBean").getValue(context.getELContext()); - boolean nifIsDupe = false; - if (managedBean instanceof RegisterUserMBean) { - RegisterUserMBean ruBean = RegisterUserMBean.class.cast(managedBean); - nifIsDupe = ruBean.checkNIFDuplicated(strValue, ruBean.getUserType()); - } else if (managedBean instanceof UpdateProfileMBean) { - UpdateProfileMBean upBean = UpdateProfileMBean.class.cast(managedBean); - nifIsDupe = upBean.checkNIFDuplicated(strValue, upBean.getUserType(), upBean.getId()); + boolean nifIsDupe = false; + ValueExpression valueExpr = comp.getValueExpression("managedBean"); + + if (valueExpr != null) { + Object managedBean = valueExpr.getValue(context.getELContext()); + + if (managedBean instanceof RegisterUserMBean) { + RegisterUserMBean ruBean = RegisterUserMBean.class.cast(managedBean); + nifIsDupe = ruBean.checkNIFDuplicated(strValue, ruBean.getUserType()); + } else if (managedBean instanceof UpdateProfileMBean) { + UpdateProfileMBean upBean = UpdateProfileMBean.class.cast(managedBean); + nifIsDupe = upBean.checkNIFDuplicated(strValue, upBean.getUserType(), upBean.getId()); + } } PrimeFaces.current().ajax().addCallbackParam("formattedNIF", strValue);