1 5 package org.exoplatform.faces.core.component.model; 6 7 import java.util.* ; 8 import java.io.IOException ; 9 import javax.faces.context.ResponseWriter ; 10 import org.exoplatform.faces.core.component.UIGrid; 11 import org.exoplatform.commons.utils.ExpressionUtil ; 12 18 public class Cell { 19 protected List attributes_ ; 20 protected String value_ ; 21 22 public Cell() { 23 24 } 25 26 public Cell (String value) { 27 value_ = value ; 28 } 29 30 public Cell(int value) { 31 value_ = Integer.toString(value) ; 32 } 33 34 public Cell(long value) { 35 value_ = Long.toString(value) ; 36 } 37 38 public Cell(float value) { 39 value_ = Float.toString(value) ; 40 } 41 42 public Cell(double value) { 43 value_ = Double.toString(value) ; 44 } 45 46 public Cell(Date value) { 47 value_ = value.toString() ; 48 } 49 50 public Cell setValue(String value) { 51 if(value == null) value_ ="" ; 52 else value_ = value ; 53 return this ; 54 } 55 56 public Cell setValue(Date value) { 57 if(value == null) value_ = "" ; 58 else value_ = value.toString() ; 59 return this ; 60 } 61 62 public Cell addAttribute(String name, String value) { 63 if(attributes_ == null) attributes_ = new ArrayList(3) ; 64 attributes_.add(new Attribute(name, value)) ; 65 return this ; 66 } 67 68 public Cell addClazz(String clazz) { 69 addAttribute("class", clazz) ; 70 return this ; 71 } 72 73 public Cell addStyle(String style) { 74 addAttribute("style", style) ; 75 return this ; 76 } 77 78 public Cell addColspan(String s) { 79 addAttribute("colspan", s) ; 80 return this ; 81 } 82 83 public Cell addRowspan(String s) { 84 addAttribute("rowspan", s) ; 85 return this ; 86 } 87 88 public Cell addWidth(String w) { 89 addAttribute("width", w) ; 90 return this ; 91 } 92 93 public Cell addAlign(String s) { 94 addAttribute("align", s) ; 95 return this ; 96 } 97 98 public Cell addValign(String s) { 99 addAttribute("valign", s) ; 100 return this ; 101 } 102 103 public Cell addHeight(String h) { 104 addAttribute("height", h) ; 105 return this ; 106 } 107 108 public class Attribute { 109 String name_ ; 110 String value_ ; 111 112 public Attribute(String name, String value) { 113 name_ = name ; 114 value_ = value ; 115 } 116 } 117 118 public void render(ResponseWriter w, ResourceBundle res, UIGrid uiGrid, String tag) throws IOException { 119 w.write('<'); w.write(tag) ; 120 if(attributes_ != null) { 121 int size = attributes_.size() ; 122 for(int i = 0; i < size ; i++) { 123 Cell.Attribute attr = (Cell.Attribute) attributes_.get(i) ; 124 w.write(" "); w.write(attr.name_); w.write("=\""); w.write(attr.value_); w.write('\"') ; 125 } 126 } 127 w.write('>') ; 128 w.write(ExpressionUtil.getExpressionValue(res,value_)) ; 129 w.write("</"); w.write(tag); w.write(">") ; 130 } 131 } | Popular Tags |