1 5 package org.exoplatform.faces.user.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 12 import org.exoplatform.container.PortalContainer ; 13 import org.exoplatform.services.organization.OrganizationService ; 14 import org.exoplatform.faces.application.ExoFacesMessage; 15 import org.exoplatform.faces.core.component.UIInput; 16 21 public class ValidUserValidator implements Validator { 22 public void validate(FacesContext context, UIComponent component, 23 Object value) throws ValidatorException { 24 String s = (String ) value ; 25 if(s == null || s.length() == 0) { 26 UIInput uiInput = (UIInput) component ; 27 Object [] args = {uiInput.getName(), s} ; 28 throw new ValidatorException(new ExoFacesMessage("#{ValidUserValidator.msg.empty-input}", args)) ; 29 } 30 PortalContainer container = PortalContainer.getInstance() ; 31 OrganizationService service = 32 (OrganizationService) container.getComponentInstanceOfType(OrganizationService.class) ; 33 try { 34 if(service.findUserByName(s) == null) { 35 UIInput uiInput = (UIInput) component ; 36 Object [] args = {uiInput.getName(), s} ; 37 throw new ValidatorException(new ExoFacesMessage("#{ValidUserValidator.msg.invalid-username}", args)) ; 38 } 39 } catch(Exception ex) { 40 throw new ValidatorException(new ExoFacesMessage(ex.getMessage())) ; 41 } 42 } 43 } | Popular Tags |