KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > user > validator > ValidGroupValidator


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

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 /**
16  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
17  * @since Aug 13, 2004
18  * @version $Id: EmptyStringValidator.java,v 1.4 2004/08/19 14:53:44 tuan08 Exp $
19  */

20 public class ValidGroupValidator implements Validator {
21   public void validate(FacesContext context, UIComponent component,
22                        Object JavaDoc value) throws ValidatorException {
23     String JavaDoc s = (String JavaDoc) value ;
24     if(s == null || s.length() == 0) {
25       UIInput uiInput = (UIInput) component ;
26       Object JavaDoc[] 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 JavaDoc[] args = {uiInput.getName(), s} ;
36         throw new ValidatorException(new ExoFacesMessage("#{ValidGroupValidator.msg.invalid-group-id}", args)) ;
37       }
38     } catch(Exception JavaDoc ex) {
39       throw new ValidatorException(new ExoFacesMessage(ex.getMessage())) ;
40     }
41   }
42 }
Popular Tags