1 16 package org.apache.myfaces.custom.isbnvalidator; 17 18 import org.apache.myfaces.util.MessageUtils; 19 20 import javax.faces.application.FacesMessage; 21 import javax.faces.component.UIComponent; 22 import javax.faces.context.FacesContext; 23 import javax.faces.validator.Validator; 24 import javax.faces.validator.ValidatorException; 25 26 40 41 public class ISBNValidator implements Validator { 42 43 46 public static final String VALIDATOR_ID = "org.apache.myfaces.validator.ISBN"; 47 51 public static final String ISBN_MESSAGE_ID = "org.apache.myfaces.ISBN.INVALID"; 52 53 56 private org.apache.commons.validator.ISBNValidator isbnValidator; 57 58 public ISBNValidator(){ 59 isbnValidator = new org.apache.commons.validator.ISBNValidator(); 60 } 61 62 66 public void validate( 67 FacesContext facesContext, 68 UIComponent uiComponent, 69 Object value) 70 throws ValidatorException { 71 72 73 if (facesContext == null) throw new NullPointerException ("facesContext"); 74 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 75 76 if (value == null) 77 { 78 return; 79 } 80 if (!isbnValidator.isValid( value.toString())) { 81 Object [] args = {value.toString()}; 82 throw new ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,ISBN_MESSAGE_ID, args)); 83 84 } 85 86 } 87 88 } 89 | Popular Tags |