KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > model > Rows


1 /***************************************************************************
2
3  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
4
5  * Please look at license.txt in info directory for more license detail. *
6
7  **************************************************************************/

8 package org.exoplatform.faces.core.component.model;
9
10 import java.io.IOException JavaDoc;
11 import java.util.*;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.core.component.UIGrid;
14
15 /**
16  * Wed, Dec 22, 2003 @ 23:14
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: Rows.java,v 1.3 2004/08/02 17:36:45 benjmestrallet Exp $
20  */

21 public class Rows implements HtmlFragment {
22   protected List columns;
23   protected DataHandler dataHandler_;
24   protected String JavaDoc evenRowClass_;
25   protected String JavaDoc oddRowClass_;
26
27   public Rows(DataHandler handler) {
28     dataHandler_ = handler;
29     columns = new ArrayList(5);
30   }
31
32   public Rows(DataHandler handler, String JavaDoc evenRowClass, String JavaDoc oddRowClass) {
33     dataHandler_ = handler;
34     columns = new ArrayList(5);
35     evenRowClass_ = evenRowClass;
36     oddRowClass_ = oddRowClass;
37   }
38
39   public Rows setEvenRowClass(String JavaDoc clazz) {
40     evenRowClass_ = clazz;
41     return this;
42   }
43
44   public Rows setOddRowClass(String JavaDoc 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 JavaDoc {
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 JavaDoc 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