Author: abelevich
Date: 2009-10-20 08:16:48 -0400 (Tue, 20 Oct 2009)
New Revision: 15732
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
Log:
move encodeTableHederFacet, encodeCaption methods to the table spec renderer
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-10-20
12:14:56 UTC (rev 15731)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-10-20
12:16:48 UTC (rev 15732)
@@ -31,8 +31,9 @@
import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.Row;
+import org.richfaces.component.Column;
import org.richfaces.component.UIDataAdaptor;
import org.richfaces.component.UIDataTable;
@@ -52,44 +53,33 @@
{"onmouseout","onRowMouseOut"}
};
+ public static final String ROW_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".rowClass";
- public static final String ROW_CLASS_KEY =
- AbstractRowsRenderer.class.getName() + ".rowClass";
+ public static final String SKIN_ROW_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".skinRowClass";
- public static final String SKIN_ROW_CLASS_KEY =
- AbstractRowsRenderer.class.getName() + ".skinRowClass";
+ public static final String CELL_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".cellClass";
- public static final String CELL_CLASS_KEY =
- AbstractRowsRenderer.class.getName() + ".cellClass";
+ public static final String SKIN_CELL_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".skinCellClass";
- public static final String SKIN_CELL_CLASS_KEY =
- AbstractRowsRenderer.class.getName() + ".skinCellClass";
+ public static final String SKIN_FIRST_ROW_CLASS_KEY =
AbstractRowsRenderer.class.getName() + ".firstRowSkinClass";
- public static final String SKIN_FIRST_ROW_CLASS_KEY =
- AbstractRowsRenderer.class.getName() + ".firstRowSkinClass";
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.ajax.repeat.DataVisitor#process(javax.faces.context.FacesContext,
- * java.lang.Object, java.lang.Object)
- */
+ public abstract void doProcess(FacesContext facesContext, TableHolder holder) throws
IOException;
+
+ public abstract void encodeOneRow(FacesContext context, TableHolder holder) throws
IOException;
+
+ public abstract void encodeCell(FacesContext context, UIComponent cell) throws
IOException;
public DataVisitResult process(FacesContext facesContext, Object rowKey, Object
argument) {
TableHolder holder = (TableHolder) argument;
UIDataAdaptor table = holder.getTable();
table.setRowKey(facesContext, rowKey);
-
- ResponseWriter writer = facesContext.getResponseWriter();
try {
- writer.startElement(HTML.TR_ELEMENT, table);
- encodeOneRow(facesContext, holder);
- writer.endElement(HTML.TR_ELEMENT);
+ doProcess(facesContext, holder);
}catch (IOException e) {
//TODO: seems we need add throws IOException ???
}
holder.nextRow();
-
return DataVisitResult.CONTINUE;
}
@@ -97,17 +87,7 @@
encodeRows(facesContext, table, new TableHolder(table));
}
-
-
- /**
- * Iterate over all rows for this table.
- *
- * @param context
- * @param component
- * @throws IOException
- */
- protected void encodeRows(FacesContext context, UIDataTable component, TableHolder
tableHolder)
- throws IOException {
+ protected void encodeRows(FacesContext context, UIDataTable component, TableHolder
tableHolder) throws IOException {
UIDataTable table = component;
Object key = table.getRowKey();
table.captureOrigValue(context);
@@ -119,25 +99,10 @@
table.restoreOrigValue(context);
}
- /**
- * @param context
- * TODO
- * @param tableHolder
- * @throws IOException
- */
- protected void doCleanup(FacesContext context, TableHolder tableHolder)
- throws IOException {
+ protected void doCleanup(FacesContext context, TableHolder tableHolder) throws
IOException {
// Hoock method for perform encoding after all rows is rendered
-
}
- public abstract void encodeOneRow(FacesContext context, TableHolder holder)
- throws IOException;
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.render.Renderer#getRendersChildren()
- */
public boolean getRendersChildren() {
return true;
}
@@ -148,49 +113,14 @@
}
}
- public void encodeCaption(FacesContext context, UIDataTable table) throws IOException {
-
- UIComponent caption = table.getCaption();
- if (caption == null) {
- return;
- }
-
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("caption", table);
-
- String captionClass = (String) table.getAttributes().get("captionClass");
- if (captionClass != null) {
- captionClass = "rich-table-caption " + captionClass;
- } else {
- captionClass = "rich-table-caption";
- }
- writer.writeAttribute("class", captionClass, "captionClass");
-
- String captionStyle = (String)
table.getAttributes().get("captionStyle");
- if (captionStyle != null) {
- writer.writeAttribute("style", captionStyle, "captionStyle");
- }
-
- renderChild(context, caption);
-
- writer.endElement("caption");
-
- }
-
- /**
- * @param context
- * @param table
- * @throws IOException
- */
-
protected void encodeRowEvents(FacesContext context, UIDataAdaptor table) throws
IOException {
- /*
+
RendererUtils utils2 = getUtils();
for (int i = 0; i < TABLE_EVENT_ATTRS.length; i++) {
String[] attrs = TABLE_EVENT_ATTRS[i];
utils2.encodeAttribute(context, table, attrs[1], attrs[0]);
}
- */
+
}
/**
@@ -304,9 +234,13 @@
requestMap.put(SKIN_CELL_CLASS_KEY, skinCellClass);
}
+
+ if(cell instanceof Column) {
+ encodeCell(context, cell);
+ } else {
+ renderChild(context, cell);
+ }
- renderChild(context, cell);
-
// Restore original values.
requestMap.put(ROW_CLASS_KEY, savedRowClass);
requestMap.put(CELL_CLASS_KEY, savedCellClass);
@@ -315,27 +249,28 @@
requestMap.put(SKIN_CELL_CLASS_KEY, savedSkinCellClass);
}
+
+ protected String cellStyleClass(FacesContext context , UIComponent component){
- protected void encodeTableHeaderFacet(FacesContext context, int columns, ResponseWriter
writer, UIComponent footer, String skinFirstRowClass, String skinRowClass, String
skinCellClass, String footerClass, String element) throws IOException {
- boolean isColgroup = footer instanceof Row;
- if (!isColgroup) {
- writer.startElement("tr", footer);
- encodeStyleClass(writer, null, skinFirstRowClass, footerClass, null);
- writer.startElement(element, footer);
- encodeStyleClass(writer, null, skinCellClass, footerClass, null);
- if (columns > 0) {
- writer.writeAttribute("colspan", String.valueOf(columns), null);
- }
- writer.writeAttribute("scope", "colgroup", null);
+ StringBuffer styleClass = new StringBuffer();
+ // Construct predefined classes
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ Object parentPredefined = requestMap.get(AbstractRowsRenderer.SKIN_CELL_CLASS_KEY);
+ if (null != parentPredefined) {
+ styleClass.append(parentPredefined).append(" ");
+ } else {
+ styleClass.append("rich-table-cell ");
}
-
- encodeCellChildren(context, footer, skinFirstRowClass, skinRowClass,
- footerClass, skinCellClass, null);
-
- if (!isColgroup) {
- writer.endElement(element);
- writer.endElement("tr");
+ // Append class from parent component.
+ Object parent = requestMap.get(AbstractRowsRenderer.CELL_CLASS_KEY);
+ if (null != parent) {
+ styleClass.append(parent).append(" ");
}
+ Object custom = component.getAttributes().get("styleClass");
+ if (null != custom) {
+ styleClass.append(custom);
+ }
+ return styleClass.toString();
}
}