Author: konstantin.mishin
Date: 2008-01-18 14:29:23 -0500 (Fri, 18 Jan 2008)
New Revision: 5475
Modified:
trunk/ui/dataTable/src/main/config/component/column.xml
trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/html/MockColumns.java
Log:
RF-1741
Modified: trunk/ui/dataTable/src/main/config/component/column.xml
===================================================================
--- trunk/ui/dataTable/src/main/config/component/column.xml 2008-01-18 19:20:34 UTC (rev
5474)
+++ trunk/ui/dataTable/src/main/config/component/column.xml 2008-01-18 19:29:23 UTC (rev
5475)
@@ -81,7 +81,19 @@
<classname>java.lang.String</classname>
<description>Attribute defines a bean property which is used for sorting of a
column</description>
</property>
+ <property>
+ <name>sortOrder</name>
+ <classname>org.richfaces.model.Ordering</classname>
+ <description>SortOrder is an enumeration of the possible sort
orderings.</description>
+ <defaultvalue>Ordering.UNSORTED</defaultvalue>
+ </property>
+ <property elonly="true">
+ <name>filterExpression</name>
+ <classname>boolean</classname>
+ <description>Attribute defines a bean property which is used for filtering of a
column</description>
+ </property>
+
<!--
<property>
<name>param</name>
Modified: trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java 2008-01-18
19:20:34 UTC (rev 5474)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java 2008-01-18
19:29:23 UTC (rev 5475)
@@ -22,27 +22,33 @@
package org.richfaces.component;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.component.SequenceDataAdaptor;
-import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.Range;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain;
-import org.richfaces.model.SortableModel;
-import org.richfaces.model.SortableRange;
+import org.richfaces.model.FilterField;
+import org.richfaces.model.ModifiableModel;
+import org.richfaces.model.Ordering;
+import org.richfaces.model.SortField2;
/**
* JSF component class
*
*/
-public abstract class UIDataTable extends SequenceDataAdaptor implements Sortable2 {
+public abstract class UIDataTable extends SequenceDataAdaptor implements Sortable2,
Filterable {
/**
* @author shura
@@ -158,16 +164,31 @@
@Override
protected ExtendedDataModel createDataModel() {
+ ExpressionFactory factory =
FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
+ ELContext context = FacesContext.getCurrentInstance().getELContext();
+ List<FilterField> filterFields = new LinkedList<FilterField>();
+ List<SortField2> sortFields = new LinkedList<SortField2>();
+ List<UIComponent> list = getChildren();
+ for (Iterator<UIComponent> iterator = list.iterator(); iterator.hasNext();) {
+ UIComponent component = iterator.next();
+ if (component instanceof org.richfaces.component.UIColumn) {
+ Column column = (Column) component;
+ ValueExpression filterExpression =
component.getValueExpression("filterExpression");
+ if (filterExpression != null) {
+ filterFields.add(new FilterField(filterExpression));
+ }
+ if (column.isSortable() && !Ordering.UNSORTED.equals(column.getSortOrder()))
{
+ ValueExpression sortExpression =
component.getValueExpression("sortExpression");
+ if (sortExpression != null) {
+ sortFields.add(new SortField2(factory.createValueExpression(context,
sortExpression.getExpressionString(), Object.class), column.getSortOrder()));
+ }
+ }
+ }
+
+ }
+ setFilterFields(filterFields);
+ setSortFields(sortFields);
ExtendedDataModel dataModel = super.createDataModel();
- return new SortableModel(dataModel);
+ return new ModifiableModel(dataModel, getVar(), getFilterFields(), getSortFields());
}
-
- @Override
- protected DataComponentState createComponentState() {
- return new DataComponentState() {
- public Range getRange() {
- return new SortableRange(getFirst(), getRows(), getVar(), getSortOrder());
- }
- };
- }
}
\ No newline at end of file
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/html/MockColumns.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/html/MockColumns.java 2008-01-18
19:20:34 UTC (rev 5474)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/html/MockColumns.java 2008-01-18
19:29:23 UTC (rev 5475)
@@ -26,6 +26,7 @@
import javax.faces.component.UIComponentBase;
import org.richfaces.component.Column;
+import org.richfaces.model.Ordering;
/**
* @author Maksim Kaszynski
@@ -38,6 +39,7 @@
}
private String sortExpression;
+ private Ordering sortOrder;
private boolean sortable;
private boolean breakbefore;
@@ -74,4 +76,12 @@
column.setId(id);
return column;
}
+
+ public Ordering getSortOrder() {
+ return sortOrder;
+ }
+
+ public void setSortOrder(Ordering sortOrder) {
+ this.sortOrder = sortOrder;
+ }
}