1 5 package org.exoplatform.faces.core.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 10 import javax.faces.component.UIComponent; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import org.exoplatform.commons.utils.ExpressionUtil; 14 import org.exoplatform.faces.core.component.UIExoComponent; 15 import org.exoplatform.faces.core.component.Node ; 16 import org.exoplatform.faces.core.component.model.Parameter; 17 18 public class SimpleTabRenderer extends NodeMenuRenderer { 19 final public void encodeChildren( FacesContext context, UIComponent component ) throws IOException { 20 ResponseWriter w = context.getResponseWriter() ; 21 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()); 22 UIExoComponent uiComponent = (UIExoComponent) component ; 23 List children = uiComponent.getChildren() ; 24 if(children.size() == 0 ) return ; 25 UIExoComponent uiSelectTab = null ; 26 27 String clazz = uiComponent.getClazz() ; 28 if (clazz == null) { 29 w.write("<div>") ; 30 } else { 31 w.write("<div class='") ; w.write(clazz) ; w.write("'>") ; 32 } 33 if (children.size() > 1) { 34 Parameter tabIdParam = new Parameter("tabId" , ""); 35 Parameter[] params = {SELECT_TAB , tabIdParam} ; 36 w.write("<ul class='"); w.write(getTabCssClass()) ; w.write("'>") ; 37 for(int i =0; i < children.size(); i++) { 38 UIExoComponent uiChild = (UIExoComponent) children.get(i) ; 39 tabIdParam.setValue(uiChild.getId()) ; 40 String label = null ; 41 if(uiChild instanceof Node) { 42 Node uiNode = (Node) uiChild ; 43 label = uiNode.getName() ; 44 } 45 if(label == null) { 46 label = ExpressionUtil.getValue(res, "UINode.label." + uiChild.getId()) ; 47 } 48 w.write("<li>") ; 49 if(uiChild.isRendered()) { 50 linkRenderer_.renderSelect(w, uiComponent, label, params) ; 51 uiSelectTab = uiChild ; 52 } else { 53 linkRenderer_.render(w, uiComponent, label, params) ; 54 } 55 w.write("</li>") ; 56 } 57 w.write("</ul>") ; 58 } else { 59 uiSelectTab = (UIExoComponent) children.get(0) ; 60 } 61 w.write("<div class='"); w.write(getTabBodyCssClass()) ; w.write("'>") ; 62 uiSelectTab.encodeBegin(context) ; 63 uiSelectTab.encodeChildren(context) ; 64 uiSelectTab.encodeEnd(context) ; 65 w.write("</div>") ; 66 w.write("</div>") ; 67 } 68 69 protected String getTabCssClass() { return "UISimpleTabs" ; } 70 71 protected String getTabBodyCssClass() { return "UISimpleTabBody" ; } 72 } | Popular Tags |