1 5 package org.exoplatform.faces.core.component.model; 6 7 import java.util.ArrayList ; 8 import java.util.ResourceBundle ; 9 import java.io.IOException ; 10 import javax.faces.context.ResponseWriter ; 11 import javax.faces.context.FacesContext; 12 import javax.faces.component.UIComponent; 13 import org.exoplatform.commons.utils.ExpressionUtil; 14 import org.exoplatform.faces.core.component.UIGrid; 15 16 22 public class ListComponentCell extends Cell { 23 private ArrayList comps_ ; 24 25 public ListComponentCell() { 26 comps_ = new ArrayList (5) ; 27 } 28 29 public ListComponentCell add(UIComponent parent, UIComponent comp) { 30 parent.getChildren().add(comp) ; 31 comps_.add(comp) ; 32 return this ; 33 } 34 35 public ListComponentCell add(Object o) { 36 comps_.add(o) ; 37 return this ; 38 } 39 40 public ListComponentCell add(HtmlFragment f) { 41 comps_.add(f) ; 42 return this ; 43 } 44 45 public void render(ResponseWriter w, ResourceBundle res, UIGrid uiGrid, String tag) throws IOException { 46 w.write("<") ; w.write(tag) ; 47 if(attributes_ != null) { 48 int size = attributes_.size() ; 49 for(int i = 0; i < size ; i++) { 50 Cell.Attribute attr = (Cell.Attribute) attributes_.get(i) ; 51 w.write(' ');w.write(attr.name_);w.write("='");w.write(attr.value_);w.write('\'') ; 52 } 53 } 54 w.write('>') ; 55 FacesContext context = FacesContext.getCurrentInstance(); 56 for (int i = 0; i < comps_.size(); i++) { 57 Object o = comps_.get(i) ; 58 if (o instanceof UIComponent) { 59 UIComponent component = (UIComponent) o; 60 component.encodeBegin(context) ; 61 component.encodeChildren(context) ; 62 component.encodeEnd(context) ; 63 } else if (o instanceof HtmlFragment){ 64 HtmlFragment f = (HtmlFragment) o ; 65 f.render(w, res, uiGrid) ; 66 } else { 67 w.write(ExpressionUtil.getExpressionValue(res,o.toString())) ; 68 } 69 } 70 w.write("</") ; w.write(tag) ; w.write(">") ; 71 } 72 } | Popular Tags |