1 5 package org.exoplatform.faces.core.component; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 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 22 public class UIInput extends UIExoComponentBase { 23 protected String name_ ; 24 protected boolean editable_ = true; 25 protected String keyDown_ ; 26 protected String keyUp_ ; 27 protected List validators_ ; 28 protected boolean error_ ; 29 protected boolean readonly_ ; 30 31 final public String getName() { return name_; } 32 33 final public UIInput setName(String name) { 34 name_ = name ; 35 return this ; 36 } 37 38 final public String getKeyDown() { return keyDown_; } 39 final public UIInput setKeyDown(String onKeyDown) { 40 keyDown_ = onKeyDown; 41 return this; 42 } 43 44 final public String getKeyUp() { return keyUp_; } 45 final public UIInput setKeyUp(String 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 (3) ; 66 validators_.add(validator) ; 67 } 68 69 protected void addComponentValidator(Class 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 (3) ; 75 validators_.add(result) ; 76 } 77 78 protected void processValidators(FacesContext context, Object 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 { } 102 public void encodeEnd(FacesContext context) throws java.io.IOException { } 103 } | Popular Tags |