1 8 package org.exoplatform.faces.core.component.model; 9 10 import java.io.IOException ; 11 import java.util.*; 12 import javax.faces.context.ResponseWriter; 13 import org.exoplatform.faces.core.component.UIGrid; 14 15 21 public class Rows implements HtmlFragment { 22 protected List columns; 23 protected DataHandler dataHandler_; 24 protected String evenRowClass_; 25 protected String oddRowClass_; 26 27 public Rows(DataHandler handler) { 28 dataHandler_ = handler; 29 columns = new ArrayList(5); 30 } 31 32 public Rows(DataHandler handler, String evenRowClass, String oddRowClass) { 33 dataHandler_ = handler; 34 columns = new ArrayList(5); 35 evenRowClass_ = evenRowClass; 36 oddRowClass_ = oddRowClass; 37 } 38 39 public Rows setEvenRowClass(String clazz) { 40 evenRowClass_ = clazz; 41 return this; 42 } 43 44 public Rows setOddRowClass(String clazz) { 45 oddRowClass_ = clazz; 46 return this; 47 } 48 49 public Rows add(Column column) { 50 columns.add(column); 51 return this; 52 } 53 54 public void render(ResponseWriter w, ResourceBundle res, UIGrid uiParent) throws IOException { 55 dataHandler_.begin(); 56 if (columns != null) { 57 w.write("<tr>"); 58 for (int i = 0; i < columns.size(); i++) { 59 Column column = (Column) columns.get(i); 60 column.renderHeader(w, res); 61 } 62 w.write("</tr>"); 63 } 64 String clazz = evenRowClass_; 65 while (dataHandler_.nextRow()) { 66 if (clazz == null) { 67 w.write("<tr>"); 68 } else { 69 w.write("<tr class='"); 70 w.write(clazz); 71 w.write("'>"); 72 } 73 for (int i = 0; i < columns.size(); i++) { 74 Column column = (Column) columns.get(i); 75 column.render(w, res, uiParent, dataHandler_); 76 } 77 w.write("</tr>"); 78 if (clazz == evenRowClass_) clazz = oddRowClass_; 79 else clazz = evenRowClass_; 80 } 81 } 82 } | Popular Tags |