Author: abelevich
Date: 2010-05-03 12:45:09 -0400 (Mon, 03 May 2010)
New Revision: 16873
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableBaseRenderer.java
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/AbstractTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ColumnGroupRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
Log:
add class whilch hold filtering/sorting process logic
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 2010-05-03
14:56:30 UTC (rev 16872)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -38,7 +38,7 @@
*
*/
public abstract class AbstractRowsRenderer extends RendererBase implements DataVisitor {
-
+
public DataVisitResult process(FacesContext context, Object rowKey, Object argument)
{
RowHolderBase holder = (RowHolderBase) argument;
Row row = holder.getRow();
@@ -55,22 +55,14 @@
protected void encodeRows(RowHolderBase rowHolder) throws IOException {
rowHolder.getRow().walk(rowHolder.getContext(), this, rowHolder);
}
-
- public void encodeRowsBegin(ResponseWriter writer, FacesContext context,
RowHolderBase holder) throws IOException {
- }
-
- public void encodeRowsEnd(ResponseWriter writer, FacesContext context, RowHolderBase
holder) throws IOException {
- }
-
+
public abstract void encodeRow(RowHolderBase rowHolder) throws IOException;
@Override
protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
throws IOException {
RowHolderBase rowHolder = createRowHolder(context, component);
- encodeRowsBegin(writer, context, rowHolder);
encodeRows(rowHolder);
- encodeRowsEnd(writer, context, rowHolder);
}
public abstract RowHolderBase createRowHolder(FacesContext context, UIComponent
component);
@@ -83,5 +75,4 @@
public boolean getRendersChildren() {
return true;
}
-
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableBaseRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableBaseRenderer.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableBaseRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -0,0 +1,274 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.Row;
+import org.richfaces.component.UIDataTableBase;
+
+
+public abstract class AbstractTableBaseRenderer extends DataTableRowsRenderer {
+
+ public static final String ROW_CLASS_KEY = "rowClass";
+
+ public static final String FIRST_ROW_CLASS_KEY = "firstRowClass";
+
+ public static final String CELL_CLASS_KEY = "cellClass";
+
+ public static final String CELL_ELEMENT_KEY = "cellElement";
+
+
+ public RowHolder encodeColumn(FacesContext context, UIColumn component,
ResponseWriter writer, RowHolder holder) throws IOException {
+
+ String parentId = holder.getDataTableId();
+
+ if (component instanceof org.richfaces.component.UIColumn) {
+ Map<String, Object> attributes = component.getAttributes();
+ if (Boolean.TRUE.equals(attributes.get("breakBefore")) &&
holder.getProcessCell() != 0) {
+ encodeRowEnd(writer, context, component);
+ holder.nextRow();
+ holder.setRowStart(true);
+ }
+ }
+
+ if (holder.isRowStart()) {
+ if (holder.getCurrentRow() == 0) {
+ encodeFirstRowStart(writer, context, parentId, component);
+ } else {
+ encodeRowStart(writer, context, parentId, component);
+ }
+
+ holder.setRowStart(false);
+ }
+
+ encodeColumnStart(writer, context, parentId, component);
+ renderChildren(context, component);
+ encodeColumnEnd(writer, context, parentId, component);
+
+ if (holder.isLastColumn()) {
+ if (holder.getCurrentRow() == 0) {
+ encodeFirstRowEnd(writer, context, component);
+ } else {
+ encodeRowEnd(writer, context, component);
+ }
+ }
+ holder.nextCell();
+
+ return holder;
+ }
+
+ public void encodeColumnStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
+ writer.startElement(getCellElement(context, parentId), component);
+ String cellClass = getCellClass(context, parentId);
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, cellClass);
+
+ if (component instanceof org.richfaces.component.UIColumn) {
+ Map<String, Object> attributes = component.getAttributes();
+
+ int rowspan = (Integer) attributes.get("rowspan");
+ if (rowspan != Integer.MIN_VALUE) {
+ writer.writeAttribute("rowspan", Integer.valueOf(rowspan),
null);
+ }
+
+ int colspan = (Integer) attributes.get("colspan");
+ if (colspan != Integer.MIN_VALUE) {
+ writer.writeAttribute("colspan", Integer.valueOf(colspan),
null);
+ }
+ }
+ }
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
+
+ if(component instanceof UIDataTableBase) {
+ UIDataTableBase dataTable = (UIDataTableBase)component;
+ int rowCount = dataTable.getRowCount();
+ if(rowCount > 0) {
+ super.doEncodeChildren(writer, context, component);
+ } else {
+ int columns = getColumnsCount(dataTable.columns());
+
+ writer.startElement(HTML.TR_ELEMENT, dataTable);
+ writer.startElement(HTML.TD_ELEM, dataTable);
+ writer.writeAttribute("colspan", columns, null);
+
+ String styleClass =
(String)dataTable.getAttributes().get("noDataStyleClass");
+ styleClass = styleClass != null ? "rich-nodata-cell " +
styleClass : "rich-nodata-cell";
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, null);
+
+ UIComponent noDataFacet = dataTable.getNoData();
+ if(noDataFacet != null && noDataFacet.isRendered() ) {
+ noDataFacet.encodeAll(context);
+ } else {
+ String noDataLabel = dataTable.getNoDataLabel();
+ if(noDataLabel != null) {
+ writer.writeText(noDataLabel, "noDataLabel");
+ }
+ }
+
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+ }
+
+ }
+
+ public void encodeColumnEnd(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
+ writer.endElement(getCellElement(context, parentId));
+ }
+
+ public void encodeFirstRowStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
+ writer.startElement(HTML.TR_ELEMENT, component);
+ getUtils().encodeId(context, component);
+ String styleClass = getFirstRowClass(context, parentId);
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
+ }
+
+ public void encodeFirstRowEnd(ResponseWriter writer, FacesContext context,
UIComponent component)throws IOException {
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+
+ public void encodeRowStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
+ writer.startElement(HTML.TR_ELEMENT, component);
+ getUtils().encodeId(context, component);
+ String styleClass = getRowClass(context, parentId);
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
+ }
+
+ public void encodeRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+
+
+ protected String getFirstRowClass(FacesContext context, String id) {
+ return get(context, id + FIRST_ROW_CLASS_KEY);
+ }
+
+ protected String getRowClass(FacesContext context, String id) {
+ return get(context, id + ROW_CLASS_KEY);
+ }
+
+ protected String getCellClass(FacesContext context, String id) {
+ return get(context, id + CELL_CLASS_KEY);
+ }
+
+ protected String getCellElement(FacesContext context, String id) {
+ return get(context, id + CELL_ELEMENT_KEY);
+ }
+
+ private String get(FacesContext context, String key) {
+ return (String)context.getAttributes().get(key);
+ }
+
+ protected void put(FacesContext context, String id, String key, String value) {
+ context.getAttributes().put(id + key, value);
+ }
+
+ //TODO nick - nested tables will not work correct
+ protected void saveRowStyles(FacesContext context, String id, String firstRowClass,
String rowClass, String cellClass) {
+ put(context, id, FIRST_ROW_CLASS_KEY, firstRowClass);
+ put(context, id, ROW_CLASS_KEY, rowClass);
+ put(context, id, CELL_CLASS_KEY, cellClass);
+ }
+
+ public void encodeStyleClass(ResponseWriter writer, FacesContext context, UIComponent
component,
+ String styleClassAttribute, String styleClass) throws IOException {
+
+ boolean isEmpty = isEmptyAttr(component, styleClassAttribute);
+ if (isEmpty && !(styleClass != null &&
styleClass.trim().length() != 0)) {
+ return;
+ }
+
+ String componentStyleClass = isEmpty ? styleClass : styleClass + "
"
+ + component.getAttributes().get(styleClassAttribute);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, componentStyleClass, null);
+ }
+
+ protected boolean isEmptyAttr(UIComponent component, String attribute) {
+ if (attribute == null) {
+ return true;
+ }
+
+ String value = (String) component.getAttributes().get(attribute);
+ return !(value != null && value.trim().length() != 0);
+ }
+
+ protected void encodeStyle(ResponseWriter writer, FacesContext context, UIComponent
component,
+ String predefinedStyles) throws IOException {
+
+ StringBuffer toEncode = new StringBuffer();
+
+ if (!isEmptyAttr(component, HTML.STYLE_ATTRIBUTE)) {
+ String style = ((String)
component.getAttributes().get(HTML.STYLE_ATTRIBUTE)).trim();
+ style = style.endsWith(";") ? style : style + ";";
+ toEncode.append(style);
+ }
+
+ if (!isEmpty(predefinedStyles)) {
+ String style = predefinedStyles.endsWith(";") ? predefinedStyles :
predefinedStyles + ";";
+ toEncode.append(style);
+ }
+
+ if (toEncode.length() > 0) {
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, toEncode.toString(), null);
+ }
+ }
+
+ protected int getColumnsCount(Iterator<UIComponent> col) {
+ int count = 0;
+ int currentLength = 0;
+ while (col.hasNext()) {
+ UIComponent component = (UIComponent) col.next();
+ if (component.isRendered()) {
+ if (component instanceof Row) {
+ // Store max calculated value of previsous rows.
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ // Calculate number of columns in row.
+ currentLength = getColumnsCount(((Row) component).columns());
+ // Store max calculated value
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ } else if (component instanceof org.richfaces.component.UIColumn) {
+ // For new row, save length of previsous.
+ Map<String, Object> attributes = component.getAttributes();
+ if (Boolean.TRUE.equals(attributes.get("breakBefore"))) {
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ }
+ Integer colspan = (Integer) attributes.get("colspan");
+ // Append colspan of this column
+ if (null != colspan && colspan.intValue() !=
Integer.MIN_VALUE) {
+ currentLength += colspan.intValue();
+ } else {
+ currentLength++;
+ }
+ } else if (component instanceof UIColumn) {
+ // UIColumn always have colspan == 1.
+ currentLength++;
+ }
+ }
+ }
+
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ return count;
+ }
+
+
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-05-03
14:56:30 UTC (rev 16872)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -16,7 +16,7 @@
@ResourceDependencies(value = { @ResourceDependency(library = "javax.faces",
name = "jsf.js"),
@ResourceDependency(name = "jquery.js"), @ResourceDependency(name =
"richfaces.js"), @ResourceDependency(name = "richfaces-event.js")})
-public abstract class AbstractTableRenderer extends DataTableRowsRenderer {
+public abstract class AbstractTableRenderer extends AbstractTableBaseRenderer {
public static final String ROW_CLASS = "rowClass";
@@ -26,6 +26,11 @@
public static final String SORTING = "sorting";
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+ decodeSortingFiltering(context, component);
+ }
/**
* Returns true if specified attribute (when present on the column) should generate
header even if it is not
* specified on the table
@@ -60,9 +65,8 @@
: getColumnsCount(table.columns());
return count;
}
-
-
+ //TODO: anton - remove?
public void encodeTableStructure(ResponseWriter writer, FacesContext context,
UIDataTableBase dataTable) throws IOException {
}
@@ -354,4 +358,37 @@
public abstract HeaderEncodeStrategy getHeaderEncodeStrategy(UIComponent column,
String tableFacetName);
public abstract boolean containsThead();
+
+ public abstract String getTableSkinClass();
+
+ public abstract String getFirstRowSkinClass();
+
+ public abstract String getRowSkinClass();
+
+ public abstract String getHeaderCellSkinClass();
+
+ public abstract String getHeaderSkinClass();
+
+ public abstract String getHeaderFirstSkinClass();
+
+ public abstract String getColumnHeaderCellSkinClass();
+
+ public abstract String getColumnHeaderSkinClass();
+
+ public abstract String getColumnHeaderFirstSkinClass();
+
+ public abstract String getFooterCellSkinClass();
+
+ public abstract String getFooterSkinClass();
+
+ public abstract String getFooterFirstSkinClass();
+
+ public abstract String getColumnFooterCellSkinClass();
+
+ public abstract String getColumnFooterSkinClass();
+
+ public abstract String getColumnFooterFirstSkinClass();
+
+ public abstract String getCellSkinClass();
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ColumnGroupRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ColumnGroupRenderer.java 2010-05-03
14:56:30 UTC (rev 16872)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ColumnGroupRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -12,7 +12,7 @@
import org.richfaces.component.UIColumnGroup;
import org.richfaces.component.UIDataTableBase;
-public class ColumnGroupRenderer extends DataTableRowsRenderer {
+public class ColumnGroupRenderer extends AbstractTableBaseRenderer {
@Override
public void encodeRow(RowHolderBase holder) throws IOException {
@@ -34,7 +34,6 @@
@Override
public RowHolderBase createRowHolder(FacesContext context, UIComponent component) {
-
UIComponent parent = component.getParent();
while(parent != null && !(parent instanceof UIDataTableBase)) {
parent = parent.getParent();
@@ -46,86 +45,4 @@
return new RowHolder(context,
parent.getClientId(context),(UIColumnGroup)component);
}
-
- // ColumnGroup component doesn't have css styles
- @Override
- public String getCellSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnFooterCellSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnFooterFirstSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnFooterSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnHeaderCellSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnHeaderFirstSkinClass() {
- return null;
- }
-
- @Override
- public String getColumnHeaderSkinClass() {
- return null;
- }
-
- @Override
- public String getFirstRowSkinClass() {
- return null;
- }
-
- @Override
- public String getFooterCellSkinClass() {
- return null;
- }
-
- @Override
- public String getFooterFirstSkinClass() {
- return null;
- }
-
- @Override
- public String getFooterSkinClass() {
- return null;
- }
-
- @Override
- public String getHeaderCellSkinClass() {
- return null;
- }
-
- @Override
- public String getHeaderFirstSkinClass() {
- return null;
- }
-
- @Override
- public String getHeaderSkinClass() {
- return null;
- }
-
- @Override
- public String getRowSkinClass() {
- return null;
- }
-
- @Override
- public String getTableSkinClass() {
- return null;
- }
-
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-05-03
14:56:30 UTC (rev 16872)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -1,305 +1,120 @@
package org.richfaces.renderkit;
-import java.io.IOException;
+import java.util.Collection;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
-import javax.faces.component.UIColumn;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
+import javax.swing.SortOrder;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.Row;
import org.richfaces.component.UIDataTableBase;
+import org.richfaces.model.SortMode;
-
public abstract class DataTableRowsRenderer extends AbstractRowsRenderer {
-
- public static final String ROW_CLASS_KEY = "rowClass";
- public static final String FIRST_ROW_CLASS_KEY = "firstRowClass";
+ private static final String FILTERING_STRING = "rich:filterString";
- public static final String CELL_CLASS_KEY = "cellClass";
+ private static final String SORTING_STRING = "rich:sortString";
- public static final String CELL_ELEMENT_KEY = "cellElement";
-
-
- public RowHolder encodeColumn(FacesContext context, UIColumn component,
ResponseWriter writer, RowHolder holder) throws IOException {
-
- String parentId = holder.getDataTableId();
-
- if (component instanceof org.richfaces.component.UIColumn) {
- Map<String, Object> attributes = component.getAttributes();
- if (Boolean.TRUE.equals(attributes.get("breakBefore")) &&
holder.getProcessCell() != 0) {
- encodeRowEnd(writer, context, component);
- holder.nextRow();
- holder.setRowStart(true);
- }
- }
+ private static final String SEPARATOR = ":";
- if (holder.isRowStart()) {
- if (holder.getCurrentRow() == 0) {
- encodeFirstRowStart(writer, context, parentId, component);
- } else {
- encodeRowStart(writer, context, parentId, component);
+ protected void decodeSortingFiltering(FacesContext context, UIComponent component) {
+ if(component instanceof UIDataTableBase) {
+ UIDataTableBase dataTableBase = (UIDataTableBase)component;
+ Map<String, String> requestMap =
context.getExternalContext().getRequestParameterMap();
+ String clientId = dataTableBase.getClientId(context);
+
+ String filtering = requestMap.get(clientId + FILTERING_STRING);
+ if(filtering != null && filtering.trim().length() > 0) {
+ decodeFiltering(context, dataTableBase, filtering);
}
-
- holder.setRowStart(false);
- }
-
- encodeColumnStart(writer, context, parentId, component);
- renderChildren(context, component);
- encodeColumnEnd(writer, context, parentId, component);
-
- if (holder.isLastColumn()) {
- if (holder.getCurrentRow() == 0) {
- encodeFirstRowEnd(writer, context, component);
- } else {
- encodeRowEnd(writer, context, component);
+
+ String sorting = requestMap.get(clientId + SORTING_STRING);
+ if(sorting != null && sorting.trim().length() > 0) {
+ decodeSorting(context, dataTableBase, sorting);
}
}
- holder.nextCell();
-
- return holder;
}
- public void encodeColumnStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
- writer.startElement(getCellElement(context, parentId), component);
- String cellClass = getCellClass(context, parentId);
- encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, cellClass);
-
- if (component instanceof org.richfaces.component.UIColumn) {
- Map<String, Object> attributes = component.getAttributes();
-
- int rowspan = (Integer) attributes.get("rowspan");
- if (rowspan != Integer.MIN_VALUE) {
- writer.writeAttribute("rowspan", Integer.valueOf(rowspan),
null);
+ protected void decodeFiltering(FacesContext context, UIDataTableBase dataTableBase,
String value) {
+ String[] values = value.split(SEPARATOR);
+ if (Boolean.parseBoolean(values[2])) {
+ for (Iterator<UIComponent> iterator = dataTableBase.columns();
iterator.hasNext();) {
+ UIComponent column = iterator.next();
+ if (values[0].equals(column.getId())) {
+ updateAttribute(context, column, "filterValue",
values[1]);
+ } else {
+ updateAttribute(context, column, "filterValue", null);
+ }
}
-
- int colspan = (Integer) attributes.get("colspan");
- if (colspan != Integer.MIN_VALUE) {
- writer.writeAttribute("colspan", Integer.valueOf(colspan),
null);
- }
+ } else {
+ updateAttribute(context, dataTableBase.findComponent(values[0]),
"filterValue", values[1]);
}
+
context.getPartialViewContext().getRenderIds().add(dataTableBase.getClientId(context)); //
TODO Use partial re-rendering here.
}
- @Override
- protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
-
- if(component instanceof UIDataTableBase) {
- UIDataTableBase dataTable = (UIDataTableBase)component;
- int rowCount = dataTable.getRowCount();
- if(rowCount > 0) {
- super.doEncodeChildren(writer, context, component);
- } else {
- int columns = getColumnsCount(dataTable.columns());
-
- writer.startElement(HTML.TR_ELEMENT, dataTable);
- writer.startElement(HTML.TD_ELEM, dataTable);
- writer.writeAttribute("colspan", columns, null);
-
- String styleClass =
(String)dataTable.getAttributes().get("noDataStyleClass");
- styleClass = styleClass != null ? "rich-nodata-cell " +
styleClass : "rich-nodata-cell";
-
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, null);
-
- UIComponent noDataFacet = dataTable.getNoData();
- if(noDataFacet != null && noDataFacet.isRendered() ) {
- noDataFacet.encodeAll(context);
+ protected void decodeSorting(FacesContext context, UIDataTableBase dataTableBase,
String value) {
+ List<Object> sortPriority = new LinkedList<Object>();
+ String[] values = value.split(SEPARATOR);
+ if (Boolean.parseBoolean(values[2]) ||
SortMode.single.equals(dataTableBase.getSortMode())) {
+ for (Iterator<UIComponent> iterator = dataTableBase.columns();
iterator.hasNext();) {
+ UIComponent column = iterator.next();
+ if (values[0].equals(column.getId())) {
+ updateSortOrder(context, column, values[1]);
+ sortPriority.add(values[0]);
} else {
- String noDataLabel = dataTable.getNoDataLabel();
- if(noDataLabel != null) {
- writer.writeText(noDataLabel, "noDataLabel");
- }
+ updateAttribute(context, column, "sortOrder",
SortOrder.UNSORTED);
}
-
- writer.endElement(HTML.TD_ELEM);
- writer.endElement(HTML.TR_ELEMENT);
}
+ } else {
+ updateSortOrder(context, dataTableBase.findComponent(values[0]), values[1]);
+ Collection<?> priority = dataTableBase.getSortPriority();
+ if (priority != null) {
+ priority.remove(values[0]);
+ sortPriority.addAll(priority);
+ }
+ sortPriority.add(values[0]);
}
-
+ updateAttribute(context, dataTableBase, "sortPriority", sortPriority);
+
context.getPartialViewContext().getRenderIds().add(dataTableBase.getClientId(context)); //
TODO Use partial re-rendering here.
}
-
- public void encodeColumnEnd(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
- writer.endElement(getCellElement(context, parentId));
- }
- public void encodeFirstRowStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
- writer.startElement(HTML.TR_ELEMENT, component);
- getUtils().encodeId(context, component);
- String styleClass = getFirstRowClass(context, parentId);
- encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
- }
-
- public void encodeFirstRowEnd(ResponseWriter writer, FacesContext context,
UIComponent component)throws IOException {
- writer.endElement(HTML.TR_ELEMENT);
- }
-
- public void encodeRowStart(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
- writer.startElement(HTML.TR_ELEMENT, component);
- getUtils().encodeId(context, component);
- String styleClass = getRowClass(context, parentId);
- encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
- }
-
- public void encodeRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- writer.endElement(HTML.TR_ELEMENT);
- }
-
-
- protected String getFirstRowClass(FacesContext context, String id) {
- return get(context, id + FIRST_ROW_CLASS_KEY);
- }
-
- protected String getRowClass(FacesContext context, String id) {
- return get(context, id + ROW_CLASS_KEY);
- }
-
- protected String getCellClass(FacesContext context, String id) {
- return get(context, id + CELL_CLASS_KEY);
- }
-
- protected String getCellElement(FacesContext context, String id) {
- return get(context, id + CELL_ELEMENT_KEY);
- }
-
- private String get(FacesContext context, String key) {
- return (String)context.getAttributes().get(key);
- }
-
- protected void put(FacesContext context, String id, String key, String value) {
- context.getAttributes().put(id + key, value);
- }
-
- //TODO nick - nested tables will not work correct
- protected void saveRowStyles(FacesContext context, String id, String firstRowClass,
String rowClass, String cellClass) {
- put(context, id, FIRST_ROW_CLASS_KEY, firstRowClass);
- put(context, id, ROW_CLASS_KEY, rowClass);
- put(context, id, CELL_CLASS_KEY, cellClass);
- }
-
- public void encodeStyleClass(ResponseWriter writer, FacesContext context, UIComponent
component,
- String styleClassAttribute, String styleClass) throws IOException {
-
- boolean isEmpty = isEmptyAttr(component, styleClassAttribute);
- if (isEmpty && !(styleClass != null &&
styleClass.trim().length() != 0)) {
- return;
+ private void updateSortOrder(FacesContext context, UIComponent component, String
value) {
+ SortOrder sortOrder = SortOrder.ASCENDING;
+ try {
+ sortOrder = SortOrder.valueOf(value);
+ } catch (IllegalArgumentException e) {
+ // If value isn't name of enum constant of SortOrder, toggle sortOrder of
column.
+ if
(SortOrder.ASCENDING.equals(component.getAttributes().get("sortOrder"))) {
+ sortOrder = SortOrder.DESCENDING;
}
-
- String componentStyleClass = isEmpty ? styleClass : styleClass + "
"
- + component.getAttributes().get(styleClassAttribute);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, componentStyleClass, null);
- }
-
- protected boolean isEmptyAttr(UIComponent component, String attribute) {
- if (attribute == null) {
- return true;
}
-
- String value = (String) component.getAttributes().get(attribute);
- return !(value != null && value.trim().length() != 0);
+ updateAttribute(context, component, "sortOrder", sortOrder);
}
-
- protected void encodeStyle(ResponseWriter writer, FacesContext context, UIComponent
component,
- String predefinedStyles) throws IOException {
-
- StringBuffer toEncode = new StringBuffer();
-
- if (!isEmptyAttr(component, HTML.STYLE_ATTRIBUTE)) {
- String style = ((String)
component.getAttributes().get(HTML.STYLE_ATTRIBUTE)).trim();
- style = style.endsWith(";") ? style : style + ";";
- toEncode.append(style);
- }
-
- if (!isEmpty(predefinedStyles)) {
- String style = predefinedStyles.endsWith(";") ? predefinedStyles :
predefinedStyles + ";";
- toEncode.append(style);
- }
-
- if (toEncode.length() > 0) {
- writer.writeAttribute(HTML.STYLE_ATTRIBUTE, toEncode.toString(), null);
- }
- }
- protected int getColumnsCount(Iterator<UIComponent> col) {
- int count = 0;
- int currentLength = 0;
- while (col.hasNext()) {
- UIComponent component = (UIComponent) col.next();
- if (component.isRendered()) {
- if (component instanceof Row) {
- // Store max calculated value of previsous rows.
- if (currentLength > count) {
- count = currentLength;
- }
- // Calculate number of columns in row.
- currentLength = getColumnsCount(((Row) component).columns());
- // Store max calculated value
- if (currentLength > count) {
- count = currentLength;
- }
- currentLength = 0;
- } else if (component instanceof org.richfaces.component.UIColumn) {
- // For new row, save length of previsous.
- Map<String, Object> attributes = component.getAttributes();
- if (Boolean.TRUE.equals(attributes.get("breakBefore"))) {
- if (currentLength > count) {
- count = currentLength;
- }
- currentLength = 0;
- }
- Integer colspan = (Integer) attributes.get("colspan");
- // Append colspan of this column
- if (null != colspan && colspan.intValue() !=
Integer.MIN_VALUE) {
- currentLength += colspan.intValue();
- } else {
- currentLength++;
- }
- } else if (component instanceof UIColumn) {
- // UIColumn always have colspan == 1.
- currentLength++;
+ protected void updateAttribute(FacesContext context, UIComponent component, String
attribute, Object value) {
+ Object oldValue = component.getAttributes().get(attribute);
+ if ((oldValue != null && !oldValue.equals(value)) || (oldValue == null
&& value != null)) {
+ ELContext elContext = context.getELContext();
+ ValueExpression ve = component.getValueExpression(attribute);
+ if (ve != null && !ve.isReadOnly(elContext)) {
+ component.getAttributes().put(attribute, null);
+ try {
+ ve.setValue(elContext, value);
+ } catch (ELException e) {
+ throw new FacesException(e);
}
+ } else {
+ component.getAttributes().put(attribute, value);
}
}
-
- if (currentLength > count) {
- count = currentLength;
- }
- return count;
}
-
-
- public abstract String getTableSkinClass();
-
- public abstract String getFirstRowSkinClass();
-
- public abstract String getRowSkinClass();
-
- public abstract String getHeaderCellSkinClass();
-
- public abstract String getHeaderSkinClass();
-
- public abstract String getHeaderFirstSkinClass();
-
- public abstract String getColumnHeaderCellSkinClass();
-
- public abstract String getColumnHeaderSkinClass();
-
- public abstract String getColumnHeaderFirstSkinClass();
-
- public abstract String getFooterCellSkinClass();
-
- public abstract String getFooterSkinClass();
-
- public abstract String getFooterFirstSkinClass();
-
- public abstract String getColumnFooterCellSkinClass();
-
- public abstract String getColumnFooterSkinClass();
-
- public abstract String getColumnFooterFirstSkinClass();
-
- public abstract String getCellSkinClass();
-
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-05-03
14:56:30 UTC (rev 16872)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-05-03
16:45:09 UTC (rev 16873)
@@ -27,7 +27,6 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -35,9 +34,6 @@
import java.util.List;
import java.util.Map;
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
@@ -45,7 +41,6 @@
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.ResponseWriter;
-import javax.swing.SortOrder;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
@@ -59,13 +54,12 @@
import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.context.ExtendedVisitContext;
-import org.richfaces.model.SortMode;
@ResourceDependencies({ @ResourceDependency(library = "javax.faces", name =
"jsf-uncompressed.js"),
@ResourceDependency(name = "jquery.js"), @ResourceDependency(name =
"jquery.position.js"),
@ResourceDependency(name = "richfaces.js"), @ResourceDependency(name =
"extendedDataTable.js"),
@ResourceDependency(name = "extendedDataTable.css") })
-public class ExtendedDataTableRenderer extends AbstractRowsRenderer implements
MetaComponentRenderer {
+public class ExtendedDataTableRenderer extends DataTableRowsRenderer implements
MetaComponentRenderer {
private static enum PartName {
frozen, normal
@@ -574,14 +568,18 @@
if (map.get(component.getClientId(context)) != null) {
updateClientFirst(context, component,
map.get("rich:clientFirst"));
}
+
+ decodeSortingFiltering(context, component);
+
+ /*
if (map.get(component.getClientId(context)) != null) {
decodeFiltering(context, component, map.get("rich:filterString"));
}
if (map.get(component.getClientId(context)) != null) {
decodeSorting(context, component, map.get("rich:sortString"));
- }
+ } */
}
-
+ /*
private void updateAttribute(FacesContext context, UIComponent component, String
attribute, Object value) {
Object oldValue = component.getAttributes().get(attribute);
if ((oldValue != null && !oldValue.equals(value)) || (oldValue == null
&& value != null)) {
@@ -611,7 +609,7 @@
}
}
updateAttribute(context, component, "sortOrder", sortOrder);
- }
+ }*/
private void updateWidthOfColumns(FacesContext context, UIComponent component, String
widthString) {
if (widthString != null && widthString.length() > 0) {
@@ -644,6 +642,7 @@
}
}
+ /*
private void decodeFiltering(FacesContext context, UIComponent component, String
value) {
if (value != null && value.length() > 0) {
String[] values = value.split(":");
@@ -663,7 +662,7 @@
context.getPartialViewContext().getRenderIds().add(component.getClientId(context)); //
TODO Use partial re-rendering here.
}
}
-
+ *
private void decodeSorting(FacesContext context, UIComponent component, String value)
{
if (value != null && value.length() > 0) {
UIDataTableBase table = (UIDataTableBase) component;
@@ -691,7 +690,7 @@
updateAttribute(context, component, "sortPriority", sortPriority);
context.getPartialViewContext().getRenderIds().add(component.getClientId(context)); //
TODO Use partial re-rendering here.
}
- }
+ } */
/**
* @deprecated