1 5 package org.exoplatform.faces.core.validator; 6 7 import javax.faces.component.UIComponent; 8 import javax.faces.context.FacesContext; 9 import javax.faces.validator.Validator; 10 import javax.faces.validator.ValidatorException; 11 import org.exoplatform.faces.application.ExoFacesMessage; 12 import org.exoplatform.faces.core.component.UIInput; 13 import org.exoplatform.faces.core.component.UIForm; 14 19 public class EmptyFieldValidator implements Validator { 20 public void validate(FacesContext context, 21 UIComponent component, 22 Object value) throws ValidatorException { 23 if(component instanceof UIForm) { 24 if(value instanceof UIForm.IntegerField) { 25 } else if(value instanceof UIForm.StringField) { 26 UIForm.StringField field = (UIForm.StringField) value ; 27 String s = field.getValue() ; 28 if(s == null || s.length() == 0) { 29 Object [] args = {field.getName()} ; 30 field.setError(true) ; 31 throw new ValidatorException(new ExoFacesMessage("#{EmptyStringValidator.msg.empty-input}", args)) ; 32 } 33 } 34 } else { 35 String s = (String ) value ; 36 if(s == null || s.length() == 0) { 37 UIInput uiInput = (UIInput) component ; 38 Object [] args = {uiInput.getName()} ; 39 throw new ValidatorException(new ExoFacesMessage("#{EmptyStringValidator.msg.empty-input}", args)) ; 40 } 41 } 42 } 43 } | Popular Tags |