1 5 package org.exoplatform.faces.core.component; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import javax.faces.component.UIComponent; 10 import javax.faces.component.UIComponentBase; 11 import javax.faces.context.ExternalContext; 12 import javax.faces.context.FacesContext; 13 import javax.faces.render.Renderer; 14 import org.exoplatform.Constants; 15 import org.exoplatform.container.SessionContainer; 16 import org.exoplatform.faces.UIComponentFactory; 17 import org.exoplatform.faces.context.PortletExternalContext; 18 import org.exoplatform.faces.core.Util; 19 import org.exoplatform.faces.core.renderer.html.Decorator; 20 import org.exoplatform.portal.session.RequestInfo; 21 import org.exoplatform.text.template.DataHandler; 22 import org.exoplatform.text.template.xhtml.Element; 23 24 30 public class UIExoComponentBase extends UIComponentBase implements UIExoComponent { 31 private String baseURL_ ; 32 private String clazz_; 33 private Decorator decorator_ ; 34 private transient Renderer cacheRenderer_ ; 35 36 public String getClazz() { return clazz_ ; } 37 public UIExoComponent setClazz(String clazz) { 38 clazz_ = clazz ; 39 return this ; 40 } 41 42 public String getFamily() { return UIExoComponent.COMPONENT_FAMILY ; } 43 44 public boolean canDecodeInvalidState() { return true ; } 45 46 public UIExoComponent setDecorator(Decorator decorator) { 47 decorator_ = decorator ; 48 return this ; 49 } 50 51 public void processDecodes(FacesContext context) { 52 List children = getChildren() ; 53 for(int i = 0 ; i < children.size(); i++) { 54 UIComponent child = (UIComponent) children.get(i); 55 if (child.isRendered()) { 56 child.processDecodes(context) ; 57 if (context.getRenderResponse()) return ; 58 } 59 } 60 decode(context) ; 61 } 62 63 public void setRendererType(String type) { 64 cacheRenderer_ = null ; 65 super.setRendererType(type) ; 66 } 67 68 protected Renderer getRenderer(FacesContext context) { 69 if(cacheRenderer_ == null) { 70 cacheRenderer_ = Util.getRenderer(context, getRendererType(), getFamily()); 71 } 72 return cacheRenderer_ ; 73 } 74 75 public UIExoComponent findComponentById(String id) { 76 return ComponentUtil.findComponentById(this, id) ; 77 } 78 79 public UIExoComponent findRenderedComponentById(String id) { 80 return ComponentUtil.findRenderedComponentById(this, id) ; 81 } 82 83 84 public UIComponent getAncestorOfType(Class classType) { 85 return ComponentUtil.getAncestorOfType(this, classType) ; 86 } 87 88 public Object getChildComponentOfType(Class classType) { 89 return ComponentUtil.getChildComponentOfType(this, classType) ; 90 } 91 92 public void setRenderedComponent(String id) { 93 ComponentUtil.setRenderedComponent(this, id) ; 94 } 95 96 public void setRenderedComponent(Class type) { 97 ComponentUtil.setRenderedComponent(this, type) ; 98 } 99 100 public void setRenderedSibling(Class type) { 101 ComponentUtil.setRenderedSibling(this, type) ; 102 } 103 104 public UIComponent getSibling(Class type) { 105 return ComponentUtil.getSibling(this, type) ; 106 } 107 108 public String getBaseURL(FacesContext context) { 109 if (baseURL_ == null) { 110 ExternalContext econtext = context.getExternalContext() ; 111 if(econtext instanceof PortletExternalContext) { 112 baseURL_ = econtext.encodeActionURL("") ; 113 baseURL_ += Constants.AMPERSAND + UICOMPONENT + "=" + getId() ; 114 } else { 115 RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class); 116 baseURL_ = rinfo.getOwnerURI(); 117 baseURL_ += "?" + UICOMPONENT + "=" + getId() ; 118 } 119 } 120 return baseURL_ ; 121 } 122 123 public String getBaseURL() { return getBaseURL(FacesContext.getCurrentInstance()); } 124 125 public void decorate(FacesContext context) throws IOException { 126 if(decorator_ != null) { 127 decorator_.decorate(context, this) ; 128 } else { 129 encodeBegin(context) ; 130 encodeChildren(context) ; 131 encodeEnd(context) ; 132 } 133 } 134 135 public UIExoComponent addChild(Class cl) throws Exception { 136 UIExoComponent uiComponent = UIComponentFactory.createComponent(cl) ; 137 getChildren().add(uiComponent) ; 138 uiComponent.registerActionListener(this) ; 139 uiComponent.registerComponentObserver(this) ; 140 return uiComponent ; 141 } 142 143 public void registerActionListener(UIExoComponent parent) { 144 145 } 146 147 public void registerComponentObserver(UIExoComponent parent) { 148 149 } 150 151 public DataHandler getDataHandler(Class classType) { 152 throw new RuntimeException ("You need to override this method and return at least one default data handler") ; 153 } 154 155 public Element getTemplate() { 156 throw new RuntimeException ("You need to override this method") ; 157 } 158 } 159 | Popular Tags |