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