cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jre...@apache.org
Subject svn commit: r933404 - /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
Date Mon, 12 Apr 2010 20:52:15 GMT
Author: jreijn
Date: Mon Apr 12 20:52:15 2010
New Revision: 933404

URL: http://svn.apache.org/viewvc?rev=933404&view=rev
Log:
COCOON-2035: Null values cause NPE in the RepeaterJXPathSorter when trying to compare values

Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java?rev=933404&r1=933403&r2=933404&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
Mon Apr 12 20:52:15 2010
@@ -16,19 +16,12 @@
  */
 package org.apache.cocoon.forms.binding;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.cocoon.forms.formmodel.Repeater.RepeaterRow;
-
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 
+import java.util.*;
+
 /**
  * @version $Id$
  */
@@ -67,7 +60,7 @@ public class RepeaterJXPathAdapter imple
 		}
 		String path = findPathFor(field);
 		if (path == null) throw new IllegalStateException("Cannot find a path for sorting on widget
" + field);
-		RepeaterSorter sort = new RepeaterJXPathSorter(path, field);
+		RepeaterSorter sort = new RepeaterJXPathSorter(path, field, false);
 		if (sortedItems == null) {
 			List tsortedItems = new ArrayList();
 			int i = 0;
@@ -150,14 +143,27 @@ public class RepeaterJXPathAdapter imple
 
 	}
 
+
+    /**
+     * Sorter for JXPath based repeaters
+     */
 	static class RepeaterJXPathSorter implements RepeaterSorter {
 
 		private String path;
 		private String field;
+        private boolean nullsAreHigher;
 
-		public RepeaterJXPathSorter(String path, String field) {
+        /**
+         * JXPath based sorter for repeater
+         * @param path the path of the field to sort on
+         * @param field the name of the field to sort on
+         * @param nullsAreHigher indicates if null values are seen as higher then other values.
+         * When this value is set to false, it  means that nulls are lower than anything
else.
+         */
+        public RepeaterJXPathSorter(String path, String field, boolean nullsAreHigher) {
 			this.path = path;
 			this.field = field;
+            this.nullsAreHigher = nullsAreHigher;
 		}
 
 		public void setCollection(Collection c) {
@@ -181,6 +187,13 @@ public class RepeaterJXPathAdapter imple
 				val2 = i2.getContext().getValue(path);
 			}
 
+			if(val1 == null) {
+                return (this.nullsAreHigher ? 1 : -1);
+            }
+	        if(val2 == null) {
+                return (this.nullsAreHigher ? -1 : 1);
+            }
+			
             if (val1 instanceof Comparable) {
                 return ((Comparable) val1).compareTo(val2);
             }



Mime
View raw message