Author: sergeyhalipov
Date: 2008-02-28 05:48:33 -0500 (Thu, 28 Feb 2008)
New Revision: 6394
Added:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
Modified:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
Log:
Rendering of table headers. Some optimization.
Modified:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2008-02-28
10:40:04 UTC (rev 6393)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2008-02-28
10:48:33 UTC (rev 6394)
@@ -138,6 +138,10 @@
throws IOException {
int t_colCount = 0;
String spacerUrl = getResource(SPACER_PATH).getUri(context, null);
+
+ HeaderEncodeStrategy richEncodeStrategy = new RichHeaderEncodeStrategy();
+ HeaderEncodeStrategy simpleEncodeStrategy = new SimpleHeaderEncodeStrategy();
+
while (headers.hasNext()) {
UIComponent column = (UIComponent) headers.next();
if((Integer)column.getAttributes().get("colspan")!=null){
@@ -158,65 +162,21 @@
writer.writeAttribute("scope", "col", null);
getUtils().encodeAttribute(context, column, "colspan");
- boolean richHeader = column instanceof org.richfaces.component.UIColumn
- && "header".equals(facetName);
boolean sortableColumn = column.getValueExpression("comparator") != null
|| column.getValueExpression("sortBy") != null;
- if (richHeader) {
- org.richfaces.component.UIColumn col =
- (org.richfaces.component.UIColumn) column;
- String clientId = col.getClientId(context) + facetName;
- writer.writeAttribute("id", clientId, null);
-
- writer.startElement(HTML.DIV_ELEM, column);
-
- if (sortableColumn) {
- if (col.isSelfSorted()) {
- writer.writeAttribute(HTML.onclick_ATTRIBUTE, buildAjaxFunction(context, column,
true)
- .toString(), null);
- writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-table-cursor-pointer",
null);
- }
- writer.startElement(HTML.SPAN_ELEM, column);
- String spanClass = "";
- if (Ordering.ASCENDING.equals(col.getSortOrder())) {
- spanClass = "dr-table-header-sort-up dr-table-sortable-header";
- } else if (Ordering.DESCENDING.equals(col.getSortOrder())) {
- spanClass = "dr-table-header-sort-down dr-table-sortable-header";
- }
- writer.writeAttribute(HTML.class_ATTRIBUTE, spanClass, null);
- }
- }
+ HeaderEncodeStrategy strategy = (column instanceof org.richfaces.component.UIColumn
+ && "header".equals(facetName)) ? richEncodeStrategy :
simpleEncodeStrategy;
+ strategy.encodeBegin(context, writer, column, facetName, sortableColumn);
+
UIComponent facet = column.getFacet(facetName);
if (facet != null) {
renderChild(context, facet);
}
- if (richHeader) {
- org.richfaces.component.UIColumn col =
- (org.richfaces.component.UIColumn) column;
- if (sortableColumn) {
- if (Ordering.ASCENDING.equals(col.getSortOrder()) ||
- Ordering.DESCENDING.equals(col.getSortOrder())) {
- writer.startElement(HTML.IMG_ELEMENT, column);
- writer.writeAttribute(HTML.src_ATTRIBUTE, spacerUrl, null);
- writer.writeAttribute(HTML.width_ATTRIBUTE, "16", null);
- writer.endElement(HTML.IMG_ELEMENT);
- }
- writer.endElement(HTML.SPAN_ELEM);
- }
-
- writer.endElement(HTML.DIV_ELEM);
-
- if (col.getFilterMethod() == null
- && col.getValueExpression("filterExpression") == null
- && col.getValueExpression("filterBy") != null) {
-
- writer.startElement(HTML.DIV_ELEM, column);
- addInplaceInput(context, column, buildAjaxFunction(context, column, false));
- writer.endElement(HTML.DIV_ELEM);
- }
- }
+
+ strategy.encodeEnd(context, writer, column, facetName, sortableColumn, spacerUrl);
+
writer.endElement(element);
@@ -520,9 +480,10 @@
}
}
- protected void addInplaceInput(FacesContext context, UIComponent column, StringBuffer
buffer)
- throws IOException {
- UIInput filterValueInput = (UIInput)column.getFacet(FILTER_INPUT_FACET_NAME);
+ protected void addInplaceInput(FacesContext context, UIComponent column,
+ StringBuffer buffer) throws IOException {
+ UIInput filterValueInput = (UIInput) column
+ .getFacet(FILTER_INPUT_FACET_NAME);
boolean inplaceInput = true;
if (null == filterValueInput) {
try {
@@ -536,17 +497,17 @@
column.getFacets().put(FILTER_INPUT_FACET_NAME, filterValueInput);
}
String onkeydownEvent = inplaceInput ? "oninputkeydown" :
"onkeydown";
-
+
filterValueInput.getAttributes().put("onchange", buffer.toString());
filterValueInput.getAttributes().put(onkeydownEvent,
"RichFaces.blurFilterInput(event);");
filterValueInput.setValue(column.getAttributes().get("filterValue"));
-
+
getUtils().encodeBeginFormIfNessesary(context, column);
renderChild(context, filterValueInput);
getUtils().encodeEndFormIfNessesary(context, column);
}
- private StringBuffer buildAjaxFunction(FacesContext context, UIComponent column, boolean
sortable) {
+ protected StringBuffer buildAjaxFunction(FacesContext context, UIComponent column,
boolean sortable) {
UIComponent table = column.getParent();
String id = table.getClientId(context);
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(table, context);
@@ -562,4 +523,78 @@
return buffer;
}
+
+ protected class SimpleHeaderEncodeStrategy implements HeaderEncodeStrategy {
+
+ public void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+
+ }
+
+ public void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn, String spacelUrl)
+ throws IOException {
+
+ }
+
+
+ }
+
+ protected class RichHeaderEncodeStrategy implements HeaderEncodeStrategy {
+
+ public void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn)
+ throws IOException {
+ org.richfaces.component.UIColumn col =
+ (org.richfaces.component.UIColumn) column;
+ String clientId = col.getClientId(context) + facetName;
+ writer.writeAttribute("id", clientId, null);
+
+ writer.startElement(HTML.DIV_ELEM, column);
+
+ if (sortableColumn) {
+ if (col.isSelfSorted()) {
+ writer.writeAttribute(HTML.onclick_ATTRIBUTE, buildAjaxFunction(context, column,
true)
+ .toString(), null);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-table-cursor-pointer",
null);
+ }
+ writer.startElement(HTML.SPAN_ELEM, column);
+ String spanClass = "";
+ if (Ordering.ASCENDING.equals(col.getSortOrder())) {
+ spanClass = "dr-table-header-sort-up dr-table-sortable-header";
+ } else if (Ordering.DESCENDING.equals(col.getSortOrder())) {
+ spanClass = "dr-table-header-sort-down dr-table-sortable-header";
+ }
+ writer.writeAttribute(HTML.class_ATTRIBUTE, spanClass, null);
+ }
+ }
+
+ public void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn, String spacerUrl)
throws IOException {
+ org.richfaces.component.UIColumn col =
+ (org.richfaces.component.UIColumn) column;
+ if (sortableColumn) {
+ if (Ordering.ASCENDING.equals(col.getSortOrder()) ||
+ Ordering.DESCENDING.equals(col.getSortOrder())) {
+ writer.startElement(HTML.IMG_ELEMENT, column);
+ writer.writeAttribute(HTML.src_ATTRIBUTE, spacerUrl, null);
+ writer.writeAttribute(HTML.width_ATTRIBUTE, "16", null);
+ writer.endElement(HTML.IMG_ELEMENT);
+ }
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+
+ writer.endElement(HTML.DIV_ELEM);
+
+ if (col.getFilterMethod() == null
+ && col.getValueExpression("filterExpression") == null
+ && col.getValueExpression("filterBy") != null) {
+
+ writer.startElement(HTML.DIV_ELEM, column);
+ addInplaceInput(context, column, buildAjaxFunction(context, column, false));
+ writer.endElement(HTML.DIV_ELEM);
+ }
+ }
+ }
}
\ No newline at end of file
Added: trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java
(rev 0)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/HeaderEncodeStrategy.java 2008-02-28
10:48:33 UTC (rev 6394)
@@ -0,0 +1,44 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+public interface HeaderEncodeStrategy {
+
+ public abstract void encodeBegin(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn) throws IOException;
+
+ public abstract void encodeEnd(FacesContext context, ResponseWriter writer,
+ UIComponent column, String facetName, boolean sortableColumn, String spacerUrl) throws
IOException;
+
+}