[richfaces-svn-commits] JBoss Rich Faces SVN: r2606 - in trunk: framework/api/src/main/java/org/richfaces/event/sort and 15 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Aug 30 09:14:59 EDT 2007


Author: maksimkaszynski
Date: 2007-08-30 09:14:59 -0400 (Thu, 30 Aug 2007)
New Revision: 2606

Added:
   trunk/ui/dataTable/src/main/java/org/richfaces/util/
   trunk/ui/dataTable/src/main/java/org/richfaces/util/ColumnUtil.java
   trunk/ui/dataTable/src/test/java/org/richfaces/util/
   trunk/ui/dataTable/src/test/java/org/richfaces/util/ColumnUtilTest.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/TestObj.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java
Modified:
   trunk/framework/api/src/main/java/org/richfaces/component/Column.java
   trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener.java
   trunk/samples/scrollableDataTableDemo/src/main/webapp/pages/scrollable-grid.xhtml
   trunk/ui/dataTable/src/main/config/component/colgroup.xml
   trunk/ui/dataTable/src/main/config/component/column.xml
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java
   trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/ScrollableDataTableRendererTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SelectionRendererContributorTest.java
   trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java
Log:
RF-734

Modified: trunk/framework/api/src/main/java/org/richfaces/component/Column.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Column.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Column.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -50,11 +50,8 @@
 	
 	public abstract void setSortable(boolean sortable);
 
-	/*
-	 * name of sort field bound to this column
-	public abstract String getName();
 	
-	public abstract void setName(String name);
+	public abstract void setSortExpression(String sortExpression);
+	public abstract String getSortExpression();
 	
-	*/
 }

Modified: trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -18,4 +18,5 @@
  */
 public interface SortListener extends FacesListener {
 	public void processSort(SortEvent e);
+	
 }

Modified: trunk/samples/scrollableDataTableDemo/src/main/webapp/pages/scrollable-grid.xhtml
===================================================================
--- trunk/samples/scrollableDataTableDemo/src/main/webapp/pages/scrollable-grid.xhtml	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/samples/scrollableDataTableDemo/src/main/webapp/pages/scrollable-grid.xhtml	2007-08-30 13:14:59 UTC (rev 2606)
@@ -44,12 +44,12 @@
 		
 		<c:set var="renderFooter" value="#{true}"/>
 		
-	     <sg:scrollableDataTable value="#{dataModel2}" 
+	     <sg:scrollableDataTable value="#{jiraService.channel.issues}" 
 	     					 var="issues" 
 	     					 frozenColCount="3" 
 	     					 first="0"
 	     					 rows="40" 
-	     					 width="800px"
+	     					 width="1800px"
 	     					 columnClasses="col"
 	     					 height="500px" hideWhenScrolling="false"> 
 	     	
@@ -70,7 +70,7 @@
      			
      		</dt:column>
      		
-     		<dt:column width="200px">
+     		<dt:column width="200px" sortExpression="#{issues.key.value}">
      		
      			<f:facet name="header">
 	   				<h:outputText value="Key"></h:outputText>
@@ -86,7 +86,7 @@
      		</dt:column>
      		
      		
-     		<dt:column width="200px">
+     		<dt:column width="200px" sortExpression="#{issues.summary}">
      			
      			<f:facet name="header">
 	   				<h:outputText value="Summary"></h:outputText>

Modified: trunk/ui/dataTable/src/main/config/component/colgroup.xml
===================================================================
--- trunk/ui/dataTable/src/main/config/component/colgroup.xml	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/dataTable/src/main/config/component/colgroup.xml	2007-08-30 13:14:59 UTC (rev 2606)
@@ -56,6 +56,11 @@
 			<description></description>
 			<defaultvalue>true</defaultvalue>
 		</property>		
+		<property disabled="true" hidden="true">
+			<name>sortExpression</name>
+			<classname>java.lang.String</classname>
+			<description></description>
+		</property>		
 		<!--
 		<property>
 			<name>param</name>

Modified: trunk/ui/dataTable/src/main/config/component/column.xml
===================================================================
--- trunk/ui/dataTable/src/main/config/component/column.xml	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/dataTable/src/main/config/component/column.xml	2007-08-30 13:14:59 UTC (rev 2606)
@@ -73,6 +73,12 @@
 			<description></description>
 			<defaultvalue>true</defaultvalue>
 		</property>		
+		<property>
+			<name>sortExpression</name>
+			<classname>java.lang.String</classname>
+			<description></description>
+		</property>		
+		
 		<!--
 		<property>
 			<name>param</name>

Added: trunk/ui/dataTable/src/main/java/org/richfaces/util/ColumnUtil.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/util/ColumnUtil.java	                        (rev 0)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/util/ColumnUtil.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,62 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.util;
+
+import javax.faces.el.ValueBinding;
+
+import org.richfaces.component.UIColumn;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ColumnUtil {
+	
+	/**
+	 * Extract sort expression from the column
+	 * 
+	 * @param column
+	 * @return logical representation of sort field assigned to column component given
+	 * In case of EL-expression, an expression string is returned instead of value - so that EL-expression can be evaluated later;
+	 * If there's literal value of dedicated attribute is specified, return it;
+	 * If attribute is not set, fall aback to component id
+	 */
+	
+	public static String getColumnSorting(UIColumn column) {
+		
+		ValueBinding binding = column.getValueBinding("sortExpression");
+		
+		if (binding != null) {
+			return binding.getExpressionString();
+		}
+		
+		String sorting = column.getSortExpression();
+		
+		if (sorting != null) {
+			return sorting;
+		}
+		
+		
+		return column.getId();
+	}
+	
+}

Added: trunk/ui/dataTable/src/test/java/org/richfaces/util/ColumnUtilTest.java
===================================================================
--- trunk/ui/dataTable/src/test/java/org/richfaces/util/ColumnUtilTest.java	                        (rev 0)
+++ trunk/ui/dataTable/src/test/java/org/richfaces/util/ColumnUtilTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.util;
+
+import java.util.Collections;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIColumn;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ColumnUtilTest extends AbstractAjax4JsfTestCase {
+
+	private UIColumn column;
+	
+	public ColumnUtilTest(String name) {
+		super(name);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+		column = (UIColumn) application.createComponent(UIColumn.COMPONENT_TYPE);
+	}
+
+	public void tearDown() throws Exception {
+		column = null;
+		super.tearDown();
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.util.ColumnUtil#getColumnSorting(org.richfaces.component.UIColumn)}.
+	 */
+	public void testGetColumnSorting() {
+		String id = "aaa";
+		column.setId(id);
+		String expression = "#{aaaaaa.aaa}";
+		String literal = "zzzzz";
+		
+		assertEquals(id, ColumnUtil.getColumnSorting(column));
+		
+		column.setValueBinding("sortExpression", application.createValueBinding(expression));
+		
+//		/externalContext.getRequestMap().put("aaaaaa", Collections.singletonMap("aaa", "000"));
+		
+		assertEquals(expression, ColumnUtil.getColumnSorting(column));
+		column.setValueBinding("sortExpression", null);
+
+		column.setSortExpression(literal);
+
+		assertEquals(literal, ColumnUtil.getColumnSorting(column));
+		
+		
+	}
+
+}

Modified: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -6,7 +6,6 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -37,8 +36,7 @@
 import org.richfaces.model.ScrollableTableDataModel;
 import org.richfaces.model.ScrollableTableDataRange;
 import org.richfaces.model.SortOrder;
-import org.richfaces.model.impl.ArrayDataModel;
-import org.richfaces.model.impl.ListDataModel;
+import org.richfaces.model.internal.ComponentSortableDataModel;
 
 
 /**
@@ -176,35 +174,8 @@
 			}
 			model = (ScrollableTableDataModel) value;
 		
-		} else	if (value instanceof List) {
-		
-			if (log.isDebugEnabled()) {
-				log.debug("Found instanceof " + value.getClass() + " - will wrap it into " + ListDataModel.class);
-			}
-
-			model = new ListDataModel((List) value);
-		
-		}else if (value instanceof Object[]) {
-		
-			if (log.isDebugEnabled()) {
-				log.debug("Found instanceof " + value.getClass() + " - will wrap it into " + ArrayDataModel.class);
-			}
-
-			model = new ArrayDataModel((Object[]) value);
-		
-		} else if (value == null) {
-			if (log.isDebugEnabled()) {
-				log.debug("Found null value - will wrap it into empty " + ListDataModel.class);
-			}
-			
-			model = new ListDataModel(Collections.EMPTY_LIST);
 		} else {
-			
-			if (log.isDebugEnabled()) {
-				log.debug("Found instanceof " + value.getClass() + " - will wrap it into singleton " + ListDataModel.class);
-			}
-			
-			model = new ListDataModel(Collections.singletonList(value));
+			model = new ComponentSortableDataModel(getVar(), value);
 		}
 		
 		if (isCacheable()) {

Modified: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -8,15 +8,16 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
-import org.richfaces.component.Column;
+import org.richfaces.component.UIColumn;
 import org.richfaces.component.UIScrollableDataTable;
 import org.richfaces.model.SortField;
 import org.richfaces.model.SortOrder;
+import org.richfaces.util.ColumnUtil;
 
 /**
+ * Implementation of sortListener for multi-column sorting
  * @author Maksim Kaszynski
  *
  */
@@ -34,11 +35,10 @@
 		UIScrollableDataTable grid = (UIScrollableDataTable) e.getComponent();
 		int columnIndex = e.getSortColumn();
 
-		UIComponent column = 
-			(UIComponent) grid.getChildren().get(columnIndex);
+		UIColumn column = 
+			(UIColumn) grid.getChildren().get(columnIndex);
 		
-		//TODO: replace with getName?
-		String name = column.getId();
+		String name = ColumnUtil.getColumnSorting(column);
 		
 		SortOrder sortOrder = grid.getSortOrder();
 		if (sortOrder == null) {

Modified: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -3,14 +3,13 @@
  */
 package org.richfaces.event.sort;
 
-import javax.faces.component.UIColumn;
-import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
-import org.richfaces.component.Column;
+import org.richfaces.component.UIColumn;
 import org.richfaces.component.UIScrollableDataTable;
 import org.richfaces.model.SortField;
 import org.richfaces.model.SortOrder;
+import org.richfaces.util.ColumnUtil;
 
 /**
  * @author Maksim Kaszynski
@@ -29,11 +28,10 @@
 	public void processSort(SortEvent e) {
 		UIScrollableDataTable grid = (UIScrollableDataTable) e.getComponent();
 		int columnIndex = e.getSortColumn();
-		UIComponent column = 
-			(UIComponent) grid.getChildren().get(columnIndex);
+		UIColumn column = 
+			(UIColumn) grid.getChildren().get(columnIndex);
 		
-		//TODO: replace with getName?
-		String name = column.getId();
+		String name = ColumnUtil.getColumnSorting(column);
 		
 		SortOrder sortOrder = grid.getSortOrder();
 		if (sortOrder == null) {

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,141 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.model.ScrollableTableDataModel;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentSortableDataModel extends ScrollableTableDataModel {
+
+	
+	/**
+	 * Wrap every list element with reflective sorting object, perform sorting, and then unwrap.
+	 * @param context
+	 * @param collection
+	 * @param sortOrder
+	 * @return
+	 */
+	protected List prepareCollection(FacesContext context, List collection, SortOrder sortOrder) {
+		
+		ObjectWrapperFactory factory = new ObjectWrapperFactory(context, var, sortOrder);
+		final SortField [] fields = sortOrder.getFields();
+
+		
+		factory.wrapList(collection);
+
+		Collections.sort(collection, new WrappedBeanComparator(fields));
+		
+		factory.unwrapList(collection);
+		
+		
+		return collection;
+	}
+	
+	
+	
+	private List wrappedList;
+	private String var;
+	
+	public ComponentSortableDataModel(String var, Object value) {
+		this.var = var;
+		setWrappedData(value);
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.richfaces.model.ScrollableTableDataModel#loadData(int, int, org.richfaces.model.SortOrder)
+	 */
+	public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+		
+		
+		List sortedCollection = sortOrder != null ?
+			prepareCollection(FacesContext.getCurrentInstance(), new ArrayList(wrappedList), sortOrder) : wrappedList;
+		
+			
+		int rc = getRowCount();
+		if (startRow < 0) {
+			startRow = 0;
+		}
+		
+		if (endRow > rc) {
+			endRow = rc;
+		}
+			
+		return sortedCollection.subList(startRow, endRow);
+	}
+
+	/* (non-Javadoc)
+	 * @see javax.faces.model.DataModel#getRowCount()
+	 */
+	public int getRowCount() {
+		// TODO Auto-generated method stub
+		return wrappedList.size();
+	}
+
+	/* (non-Javadoc)
+	 * @see javax.faces.model.DataModel#getWrappedData()
+	 */
+	public Object getWrappedData() {
+		// TODO Auto-generated method stub
+		return wrappedList;
+	}
+
+	/* (non-Javadoc)
+	 * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+	 */
+	public void setWrappedData(Object value) {
+		if (value == null) {
+			
+			wrappedList = new ArrayList();
+			
+		} else if (value instanceof Object[]) {
+
+			Object [] array = (Object[]) value;
+			
+			wrappedList = new ArrayList(array.length);
+			
+			for (int i = 0; i < array.length; i++) {
+				wrappedList.add(array[i]);
+			}
+		
+		} else if (value instanceof Collection) {
+			
+			wrappedList = new ArrayList((Collection) value);
+			
+		} else {
+			wrappedList = new ArrayList(1);
+			wrappedList.add(value);
+		}
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+/**
+ * Base interface for expressions (Literal, EL, or empty)
+ * @author Maksim Kaszynski
+ *
+ */
+abstract class Expression {
+	/**
+	 * this is expression string
+	 */
+	private String expressionString;
+	
+	public Expression(String n) {
+		expressionString = n;
+	}
+	
+	/**
+	 * 
+	 * @param base
+	 * @return result of expression evaluation
+	 */
+	public abstract Object evaluate(Object base);
+
+	public String getExpressionString() {
+		return expressionString;
+	}
+
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,46 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.Map;
+/**
+ * Object used in sorting - contains of base object, and its properties evaluated with EL
+ * @author Maksim Kaszynski
+ *
+ */
+class JavaBeanWrapper {
+	private Object wrappedObject;
+	private Map properties;
+	
+	public JavaBeanWrapper(Object o, Map props) {
+		wrappedObject = o;
+		properties = props;
+	}
+	
+	public Object getProperty(String expression) {
+		return properties.get(expression);
+	}
+	
+	public Object getWrappedObject() {
+		return wrappedObject;
+	}
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,18 @@
+package org.richfaces.model.internal;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+final class NullExpression extends Expression {
+	/**
+	 * @param n
+	 */
+	NullExpression(String n) {
+		super(n);
+	}
+
+	public Object evaluate(Object base) {
+		return null;
+	}
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,144 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.el.PropertyResolver;
+import javax.faces.webapp.UIComponentTag;
+
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+/**
+ * 
+ * class responsible for packaging objects with their properties evaluated using EL.
+ * 
+ * @author Maksim Kaszynski
+ *
+ */
+class ObjectWrapperFactory {
+
+	interface ObjectConvertor {
+		public Object convert(Object o);
+	}
+	
+	private Expression [] expressions;
+	private FacesContext context;
+	private String var;
+	private Object varValue;
+	
+	public ObjectWrapperFactory(FacesContext context, final String var, SortOrder sortOrder) {
+		
+		this.context = context;
+		
+		Application application = context.getApplication();
+		PropertyResolver resolver = application.getPropertyResolver();
+
+		this.var = var;
+		
+		SortField[] sortFields = sortOrder.getFields();
+		
+		expressions = new Expression[sortFields.length];
+		                             
+		for (int i = 0; i < sortFields.length; i++) {
+			final SortField field = sortFields[i];
+			final String name = field.getName();
+			
+			if (UIComponentTag.isValueReference(name)) {
+				
+				expressions[i] = new ValueBindingExpression(context, name, var);
+				
+			} else if (name.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+				
+				expressions[i] = new NullExpression(name);
+				
+			} else {
+				
+				expressions[i] = new SimplePropertyExpression(name, resolver);
+			}
+		}
+		
+		
+		
+	}
+	
+	void convertList(List list, ObjectConvertor c) {
+		int l = list.size();
+
+		for (int i = 0; i < l; i++) {
+			Object o = list.get(i);
+			list.set(i, c.convert(o));
+		}
+	}
+	
+	public List unwrapList(List list) {
+		
+		convertList(list, new ObjectConvertor() {
+			public Object convert(Object o) {
+				return unwrapObject(o);
+			}
+		});
+		
+		if (varValue != null){
+			context.getExternalContext().getRequestMap().put(var, varValue);
+		} else {
+			context.getExternalContext().getRequestMap().remove(var);
+		}
+		
+		return list;
+	}
+	
+	public Object unwrapObject(Object wrapper) {
+		return ((JavaBeanWrapper) wrapper).getWrappedObject();
+	}
+	
+	public List wrapList(List list) {
+		
+		varValue = context.getExternalContext().getRequestMap().get(var);
+		
+		convertList(list, new ObjectConvertor() {
+			public Object convert(Object o) {
+				return wrapObject(o);
+			}
+		});
+		
+		return list;
+	}
+	
+	public JavaBeanWrapper wrapObject(Object o) {
+		Map props = new HashMap();
+		for (int i = 0; i < expressions.length; i++) {
+			Expression expression = expressions[i];
+			
+			props.put(expression.getExpressionString(), expression.evaluate(o));
+		}
+		
+		return new JavaBeanWrapper(o, props);
+		
+	}
+	
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,37 @@
+package org.richfaces.model.internal;
+
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyResolver;
+
+/**
+ * Expression evaluated by applying application
+ * property resolver to the base object
+ * @author Maksim Kaszynski
+ *
+ */
+final class SimplePropertyExpression extends Expression {
+	/**
+	 * 
+	 */
+	private final PropertyResolver resolver;
+
+	/**
+	 * @param n
+	 * @param resolver
+	 */
+	SimplePropertyExpression(String n, PropertyResolver resolver) {
+		super(n);
+		this.resolver = resolver;
+	}
+
+	public Object evaluate(Object base) {
+		Object o = null;
+		try {
+			return resolver.getValue(base, getExpressionString());
+		} catch (EvaluationException e) {
+			
+		} 
+		
+		return o;
+	}
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,54 @@
+package org.richfaces.model.internal;
+
+import java.util.Comparator;
+
+import org.richfaces.model.SortField;
+
+/**
+ * Comparator for {@link JavaBeanWrapper} objects.
+ * Compares them using {@link SortField} sequence.
+ * 
+ * @author Maksim Kaszynski
+ *
+ */
+final class WrappedBeanComparator implements Comparator {
+	/**
+	 * 
+	 */
+	private final SortField[] fields;
+
+	/**
+	 * @param fields
+	 */
+	WrappedBeanComparator(SortField[] fields) {
+		this.fields = fields;
+	}
+
+	public int compare(Object o1, Object o2) {
+		
+		int result = 0;
+		JavaBeanWrapper w1 = (JavaBeanWrapper) o1;
+		JavaBeanWrapper w2 = (JavaBeanWrapper) o2;
+		
+		for (int i = 0; i < fields.length && result == 0; i++) {
+			
+			String prop = fields[i].getName();
+			Boolean asc = fields[i].getAscending();
+			
+			Object p1 = w1.getProperty(prop);
+			Object p2 = w2.getProperty(prop);
+			
+			if (p1 instanceof Comparable) {
+				result = ((Comparable) p1).compareTo(p2);
+			}
+			
+			if (asc != null && !asc.booleanValue()) {
+				result = -result;
+			}
+			
+		}
+		
+		
+		return result;
+	}
+}
\ No newline at end of file

Modified: trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java
===================================================================
--- trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.richfaces.component.Column;
+import org.richfaces.component.UIColumn;
 import org.richfaces.component.UIScrollableDataTable;
 import org.richfaces.event.scroll.ScrollEvent;
 import org.richfaces.event.sort.SortEvent;
@@ -28,6 +29,7 @@
 import org.richfaces.model.SortOrder;
 import org.richfaces.renderkit.CompositeRenderer;
 import org.richfaces.renderkit.RendererContributor;
+import org.richfaces.util.ColumnUtil;
 import org.richfaces.utils.TemplateLoader;
 
 
@@ -173,11 +175,10 @@
 
 			Boolean sorting = null; 
 
-			UIComponent column = 
-				(UIComponent) grid.getChildren().get(columnIndex);
+			UIColumn column = 
+				(UIColumn) grid.getChildren().get(columnIndex);
 			
-			//TODO: replace with getName?
-			String name = column.getId();
+			String name = ColumnUtil.getColumnSorting(column);
 			
 			SortOrder sortOrder = grid.getSortOrder();
 			

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,228 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIScrollableDataTable;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentSortableDataModelTest extends AbstractAjax4JsfTestCase {
+
+	private ComponentSortableDataModel model;
+	private UIScrollableDataTable table;
+	private List l;
+	private Object [] a;
+	private Object o;
+	private SortOrder sortOrder;
+	/**
+	 * @param name
+	 */
+	public ComponentSortableDataModelTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	public void setUp() throws Exception {
+		super.setUp();
+		table = (UIScrollableDataTable) application.createComponent(UIScrollableDataTable.COMPONENT_TYPE);
+		table.setVar("item");
+		model = new ComponentSortableDataModel("item", null);
+
+		facesContext.getViewRoot().getChildren().add(table);
+		
+		l = createList();
+		a = createArray();
+		o = o(20);
+		
+		
+		sortOrder = new SortOrder(new SortField[] {new SortField("name", 0,  Boolean.TRUE)});
+		
+		//model = new ComponentSortableDataModel()
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	public void tearDown() throws Exception {
+		super.tearDown();
+		model = null;
+		table = null;
+		
+		l = null; 
+		a = null;
+		o = null;
+	}
+
+	List createList() {
+		List l = new ArrayList(10);
+		for (int i = 0; i < 10; i++) {
+			l.add(o(i));
+		}
+		return l;
+	}
+
+	Object [] createArray() {
+		Object [] a = new Object[100];
+		for(int i = 0; i < a.length; i++) {
+			a[i] = o(i);
+		}
+		
+		return a;
+	}
+	
+	TestObj o(int i) {
+		return new TestObj(Integer.toString(i));
+	}
+	
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#getRowCount()}.
+	 */
+	public final void testGetRowCount() {
+		
+		model.setWrappedData(l);
+		assertEquals(l.size(), model.getRowCount());
+		
+		model.setWrappedData(a);
+		assertEquals(a.length, model.getRowCount());
+		
+		model.setWrappedData(o);
+		assertEquals(1, model.getRowCount());
+		
+		model.setWrappedData(null);
+		assertEquals(0, model.getRowCount());
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#loadData(int, int, org.richfaces.model.SortOrder)}.
+	 */
+	public final void testLoadData() {
+		model.setWrappedData(l);
+		List loaded = model.loadData(0, 5, null);
+		assertEquals(5, loaded.size());
+		loaded = model.loadData(0, 10, null);
+		assertEquals(10, loaded.size());
+		loaded = model.loadData(0, 30, null);
+		assertEquals(10, loaded.size());
+		loaded = model.loadData(5, 30, null);
+		assertEquals(5, loaded.size());
+		
+		model.setWrappedData(l);
+		loaded = model.loadData(0, 5, sortOrder);
+		assertEquals(5, loaded.size());
+		loaded = model.loadData(0, 10, sortOrder);
+		assertEquals(10, loaded.size());
+		loaded = model.loadData(0, 30, sortOrder);
+		assertEquals(10, loaded.size());
+		loaded = model.loadData(5, 30, sortOrder);
+		assertEquals(5, loaded.size());
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#prepareCollection(javax.faces.context.FacesContext, java.util.List, org.richfaces.model.SortOrder)}.
+	 */
+	public final void testPrepareCollection() {
+		model.setWrappedData(l);
+		
+		int size = l.size();
+		
+		List prepared = model.prepareCollection(facesContext, l, sortOrder);
+		assertSame(l, prepared);
+		assertEquals(size, prepared.size());
+		
+		Iterator iter = prepared.iterator();
+		
+		//must be 10 elements in collection
+		assertTrue(iter.hasNext());
+		
+		TestObj prev = (TestObj) iter.next();
+		
+		while(iter.hasNext()) {
+			
+			TestObj next = (TestObj) iter.next();
+			
+			assertTrue(next.getName().compareTo(prev.getName()) > 0);
+			
+			
+			prev = next;
+			
+		}
+		
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#ComponentSortableDataModel(javax.faces.component.UIData, java.lang.Object)}.
+	 */
+	public final void testComponentSortableDataModel() {
+		model = new ComponentSortableDataModel("item", l);
+		assertEquals(l.size(), model.getRowCount());
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#getWrappedData()}.
+	 */
+	public final void testGetWrappedData() {
+		model.setWrappedData(l);
+		assertEquals(l.size(), ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(a);
+		assertEquals(a.length, ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(o);
+		assertEquals(1, ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(null);
+		assertEquals(0, ((List) model.getWrappedData()).size());
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ComponentSortableDataModel#setWrappedData(java.lang.Object)}.
+	 */
+	public final void testSetWrappedDataObject() {
+		model.setWrappedData(l);
+		assertEquals(l.size(), ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(a);
+		assertEquals(a.length, ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(o);
+		assertEquals(1, ((List) model.getWrappedData()).size());
+		
+		model.setWrappedData(null);
+		assertEquals(0, ((List) model.getWrappedData()).size());
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaBeanWrapperTest extends TestCase {
+
+	
+	private JavaBeanWrapper wrapper;
+	final Boolean test = Boolean.TRUE;
+	final Map props = Collections.singletonMap("true", test);
+	/**
+	 * @param name
+	 */
+	public JavaBeanWrapperTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		wrapper = new JavaBeanWrapper(test, props);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		wrapper = null;
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.JavaBeanWrapper#getProperty(java.lang.String)}.
+	 */
+	public void testGetProperty() {
+		assertEquals(test, wrapper.getProperty("true"));
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.JavaBeanWrapper#getWrappedObject()}.
+	 */
+	public void testGetWrappedObject() {
+		assertEquals(test, wrapper.getWrappedObject());
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,63 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class NullExpressionTest extends TestCase {
+
+	
+	private Expression expression;
+	
+	/**
+	 * @param name
+	 */
+	public NullExpressionTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		expression = new NullExpression("_id2");
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		expression = null;
+	}
+	
+	public void testEvaluate() {
+		Object o = new Object();
+		assertNull(expression.evaluate(o));
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,198 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ObjectWrapperFactoryTest extends AbstractAjax4JsfTestCase {
+
+	
+	/**
+	 * 
+	 */
+	SortField [] sortFields;
+	SortOrder sortOrder;
+	private ObjectWrapperFactory factory;
+	private String var = "abc";
+	
+	public ObjectWrapperFactoryTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	public void setUp() throws Exception {
+		super.setUp();
+		sortFields = new SortField[3];
+		sortFields[0] = new SortField("_id1", 0, Boolean.TRUE);
+		sortFields[1] = new SortField("name", 1, Boolean.FALSE);
+		sortFields[2] = new SortField("#{" +var + ".name}", 2, Boolean.TRUE);
+		sortOrder = new SortOrder(sortFields);
+		
+		factory = new ObjectWrapperFactory(facesContext, var, sortOrder);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	public void tearDown() throws Exception {
+		super.tearDown();
+		
+		sortFields = null;
+		sortOrder = null;
+		factory = null;
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ObjectWrapperFactory#convertList(java.util.List, org.richfaces.model.internal.ObjectWrapperFactory.ObjectConvertor)}.
+	 */
+	public final void testConvertList() {
+		
+		
+		List objects = new ArrayList(); 
+		objects.add(Boolean.TRUE);
+		int size = objects.size();
+		factory.convertList(objects, new ObjectWrapperFactory.ObjectConvertor() {
+			public Object convert(Object o ) {
+				
+				return new Boolean(!((Boolean) o).booleanValue());
+			} 
+		});
+		
+		assertEquals(size, objects.size());
+		assertEquals(Boolean.FALSE, objects.get(0));
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ObjectWrapperFactory#unwrapList(java.util.List)}.
+	 */
+	public final void testUnwrapList() {
+		List objects = new ArrayList(10);
+		int [] ints = new int[10];
+		Random random = new Random();
+		for(int i = 0; i < 10; i++) {
+			ints[i] = random.nextInt();
+			objects.add(new TestObj(String.valueOf(ints[i])));
+		}
+		
+		List l1 = factory.wrapList(objects);
+		List l2 = factory.unwrapList(l1);
+		
+		assertSame(objects, l1);
+		assertSame(objects, l2);
+		assertEquals(10, l2.size());
+		
+		for(int i = 0; i < 10; i++) {
+			TestObj t = (TestObj) l2.get(i);
+			assertEquals(String.valueOf(ints[i]), t.getName());
+		}
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ObjectWrapperFactory#unwrapObject(java.lang.Object)}.
+	 */
+	public final void testUnwrapObject() {
+		
+		TestObj t = new TestObj("20");
+		
+		JavaBeanWrapper wrapper = new JavaBeanWrapper(t, new HashMap());
+		
+		Object wrapped = factory.unwrapObject(wrapper);
+		
+		assertSame(t, wrapped);
+		
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ObjectWrapperFactory#wrapList(java.util.List)}.
+	 */
+	public final void testWrapList() {
+		List objects = new ArrayList(10);
+		int [] ints = new int[10];
+		Random random = new Random();
+		for(int i = 0; i < 10; i++) {
+			ints[i] = random.nextInt();
+			objects.add(new TestObj(String.valueOf(ints[i])));
+		}
+		
+		List l1 = factory.wrapList(objects);
+		
+		assertSame(objects, l1);
+		assertEquals(10, l1.size());
+		
+		for(int i = 0; i < 10; i++) {
+			JavaBeanWrapper wrapper = (JavaBeanWrapper) l1.get(i);
+			TestObj t = (TestObj) wrapper.getWrappedObject();
+			
+			String string = String.valueOf(ints[i]);
+			
+			assertEquals(string, t.getName());
+			
+			Object prop1 = wrapper.getProperty("name"); 
+			Object prop2 = wrapper.getProperty("#{abc.name}");
+			
+			assertNotNull(prop1);
+			assertNotNull(prop2);
+			assertEquals(string, prop1);
+			assertEquals(string, prop2);
+		}
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ObjectWrapperFactory#wrapObject(java.lang.Object)}.
+	 */
+	public final void testWrapObject() {
+		TestObj t = new TestObj("20");
+		
+		
+		
+		JavaBeanWrapper wrapper = factory.wrapObject(t);
+		
+		Object wrapped = wrapper.getWrappedObject();
+		
+		assertSame(t, wrapped);
+		
+		Object prop1 = wrapper.getProperty("name"); 
+		Object prop2 = wrapper.getProperty("#{abc.name}");
+		
+		assertNotNull(prop1);
+		assertNotNull(prop2);
+		assertEquals("20", prop1);
+		assertEquals("20", prop2);
+		
+		
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,75 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimplePropertyExpressionTest extends AbstractAjax4JsfTestCase {
+
+	final static String property = "name";
+	private SimplePropertyExpression expression;
+	
+	/**
+	 * @param name
+	 */
+	public SimplePropertyExpressionTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	public void setUp() throws Exception {
+		super.setUp();
+		expression = new SimplePropertyExpression("name", application.getPropertyResolver());
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	public void tearDown() throws Exception {
+		super.tearDown();
+		expression = null;
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.SimplePropertyExpression#evaluate(java.lang.Object)}.
+	 */
+	public final void testEvaluate() {
+		TestObj testObj = new TestObj("aaaa");
+		Object prop = expression.evaluate(testObj);
+		assertNotNull(prop);
+		assertEquals("aaaa", prop);
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.Expression#getExpressionString()}.
+	 */
+	public final void testGetExpressionString() {
+		assertEquals(property, expression.getExpressionString());
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/TestObj.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/TestObj.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/TestObj.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,34 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+public class TestObj {
+	private String name;
+	
+	public TestObj(String name) {
+		this.name = name;
+	}
+
+	public String getName() {
+		return name;
+	}
+}
\ No newline at end of file

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,73 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ValueBindingExpressionTest extends AbstractAjax4JsfTestCase {
+
+	private ValueBindingExpression expression;
+	static final String var = "obj";
+	static final  String el = "#{" + var + ".name}";
+	
+	public ValueBindingExpressionTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+	 */
+	public void setUp() throws Exception {
+		super.setUp();
+		expression = new ValueBindingExpression(facesContext, el, var);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+	 */
+	public void tearDown() throws Exception {
+		super.tearDown();
+		expression = null;
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.ValueBindingExpression#evaluate(java.lang.Object)}.
+	 */
+	public final void testEvaluate() {
+		TestObj testObj = new TestObj("aaaa");
+		Object prop = expression.evaluate(testObj);
+		assertNotNull(prop);
+		assertEquals("aaaa", prop);
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.Expression#getExpressionString()}.
+	 */
+	public final void testGetExpressionString() {
+		assertEquals(el, expression.getExpressionString());
+	}
+
+}

Added: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java	                        (rev 0)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -0,0 +1,100 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - 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.model.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.richfaces.model.SortField;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class WrappedBeanComparatorTest extends TestCase {
+
+	private SortField[] sortFields;
+	private WrappedBeanComparator comparator;
+	
+	private static final int [][] testData = {{0,0}, {0,1}, {1, 0}, {1, 1} };
+	
+	private JavaBeanWrapper [] testWrapers;
+	
+	public WrappedBeanComparatorTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		sortFields = new SortField[2];
+		sortFields[0] = new SortField("a", 1, Boolean.FALSE);
+		sortFields[1] = new SortField("b", 2, Boolean.TRUE);
+
+		
+		comparator = new WrappedBeanComparator(sortFields);
+		
+		testWrapers = new JavaBeanWrapper[testData.length];
+		for(int i = 0; i < testData.length; i++) {
+			testWrapers[i] = w(testData[i]);
+		}
+		
+	}
+
+	private JavaBeanWrapper w(int [] ints) {
+		Map m = new HashMap();
+		m.put("a", new Integer(ints[0]));
+		m.put("b", new Integer(ints[1]));
+		
+		return new JavaBeanWrapper(m, m);
+	}
+	
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		sortFields = null;
+		comparator = null;
+		testWrapers = null;
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.model.internal.WrappedBeanComparator#compare(java.lang.Object, java.lang.Object)}.
+	 */
+	public final void testCompare() {
+		
+		assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+		assertTrue(comparator.compare(w(new int[] {1, 1}), w(new int [] {0, 0})) < 0);
+		assertTrue(comparator.compare(w(new int[] {0, 0}), w(new int [] {0, 1})) < 0);
+		assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 0})) == 0);
+		//assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+		//assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+		
+	}
+
+}

Modified: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/ScrollableDataTableRendererTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/ScrollableDataTableRendererTest.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/ScrollableDataTableRendererTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -68,9 +68,10 @@
 			column.getChildren().add(outputText);
 			
 			grid.getChildren().add(column);
-			grid.setFirst(0);
-			grid.setRows(40);
 		}
+
+		grid.setFirst(0);
+		grid.setRows(40);
 		
 		facesContext.getViewRoot().getChildren().add(grid);
 	}

Modified: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SelectionRendererContributorTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SelectionRendererContributorTest.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SelectionRendererContributorTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -5,16 +5,11 @@
 
 import java.util.ArrayList;
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-
 import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
 import org.apache.shale.test.mock.MockExternalContext;
 import org.richfaces.component.UIScrollableDataTable;
 import org.richfaces.model.selection.ClientSelection;
 import org.richfaces.model.selection.SelectionRange;
-import org.richfaces.renderkit.html.ScrollableDataTableBaseRenderer;
-import org.richfaces.renderkit.html.SelectionRendererContributor;
 
 /**
  * @author Maksim Kaszynski

Modified: trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java
===================================================================
--- trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java	2007-08-30 12:03:14 UTC (rev 2605)
+++ trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java	2007-08-30 13:14:59 UTC (rev 2606)
@@ -11,7 +11,7 @@
 import org.richfaces.skin.SkinFactory;
 
 /**
- * @author Anton Belevichs
+ * @author Anton Belevich
  *
  */
 public class ScrollableDataTableIconBasicTest extends AbstractAjax4JsfTestCase{




More information about the richfaces-svn-commits mailing list