1 16 package org.apache.myfaces.custom.emailvalidator; 17 18 import org.apache.myfaces.util.MessageUtils; 19 20 import org.apache.commons.validator.GenericValidator; 21 22 import javax.faces.application.FacesMessage; 23 import javax.faces.component.UIComponent; 24 import javax.faces.context.FacesContext; 25 import javax.faces.validator.Validator; 26 import javax.faces.validator.ValidatorException; 27 28 59 public class EmailValidator implements Validator { 60 61 64 public static final String VALIDATOR_ID = "org.apache.myfaces.validator.Email"; 65 69 public static final String EMAIL_MESSAGE_ID = "org.apache.myfaces.Email.INVALID"; 70 71 public EmailValidator(){ 72 } 73 74 78 public void validate( 79 FacesContext facesContext, 80 UIComponent uiComponent, 81 Object value) 82 throws ValidatorException { 83 84 85 if (facesContext == null) throw new NullPointerException ("facesContext"); 86 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 87 88 if (value == null) 89 { 90 return; 91 } 92 if (!GenericValidator.isEmail(value.toString())) { 93 Object [] args = {value.toString()}; 94 throw new ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,EMAIL_MESSAGE_ID, args)); 95 96 } 97 98 } 99 100 } 101 | Popular Tags |