KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > UIInput


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.core.component;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import javax.faces.application.FacesMessage;
10 import javax.faces.context.FacesContext;
11 import javax.faces.validator.Validator;
12 import javax.faces.validator.ValidatorException;
13 import org.exoplatform.container.PortalContainer;
14 import org.exoplatform.faces.ValidatorManager;
15 import org.exoplatform.faces.core.Util;
16 /**
17  * Wed, Dec 22, 2003 @ 23:14
18  * @author: Tuan Nguyen
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: UIInput.java,v 1.13 2004/10/23 17:46:29 tuan08 Exp $
21  */

22 public class UIInput extends UIExoComponentBase {
23   protected String JavaDoc name_ ;
24   protected boolean editable_ = true;
25   protected String JavaDoc keyDown_ ;
26   protected String JavaDoc keyUp_ ;
27   protected List JavaDoc validators_ ;
28   protected boolean error_ ;
29   protected boolean readonly_ ;
30
31   final public String JavaDoc getName() { return name_; }
32
33   final public UIInput setName(String JavaDoc name) {
34     name_ = name ;
35     return this ;
36   }
37   
38   final public String JavaDoc getKeyDown() { return keyDown_; }
39   final public UIInput setKeyDown(String JavaDoc onKeyDown) {
40       keyDown_ = onKeyDown;
41       return this;
42   }
43
44   final public String JavaDoc getKeyUp() { return keyUp_; }
45   final public UIInput setKeyUp(String JavaDoc onKeyUp) {
46       keyUp_ = onKeyUp;
47       return this;
48   }
49
50   final public boolean isEditable() { return editable_; }
51   final public UIInput setEditable(boolean b) {
52     editable_ = b ;
53     return this ;
54   }
55   
56   final public boolean isReadonly() { return readonly_; }
57   final public UIInput setReadonly(boolean b) {
58     readonly_ = b ;
59     return this ;
60   }
61   
62   public boolean hasError() { return error_ ; }
63   
64   protected void addComponentValidator(Validator validator) {
65     if(validators_ == null ) validators_ = new ArrayList JavaDoc(3) ;
66     validators_.add(validator) ;
67   }
68   
69   protected void addComponentValidator(Class JavaDoc clazz) {
70     PortalContainer pcontainer = PortalContainer.getInstance() ;
71     ValidatorManager manager =
72       (ValidatorManager) pcontainer.getComponentInstanceOfType(ValidatorManager.class) ;
73     Validator result = manager.getValidator(clazz) ;
74     if(validators_ == null ) validators_ = new ArrayList JavaDoc(3) ;
75     validators_.add(result) ;
76   }
77   
78   protected void processValidators(FacesContext context, Object JavaDoc value) {
79     if(validators_ != null) {
80       Validator validator = null ;
81       error_ = false;
82       try {
83         for(int i = 0; i < validators_.size(); i++) {
84           validator = (Validator) validators_.get(i) ;
85           validator.validate(context, this, value) ;
86         }
87       } catch(ValidatorException ex) {
88         error_ = true ;
89         FacesMessage message = ex.getFacesMessage() ;
90         InformationProvider iprovider = Util.findInformationProvider(this) ;
91         iprovider.addMessage(message) ;
92         context.renderResponse() ;
93       }
94     }
95   }
96   
97   final public void processDecodes(FacesContext context) {
98     decode(context) ;
99   }
100
101   public void encodeChildren(FacesContext context) throws java.io.IOException JavaDoc { }
102   public void encodeEnd(FacesContext context) throws java.io.IOException JavaDoc { }
103 }
Popular Tags