Author: andrei_exadel
Date: 2008-09-25 11:29:56 -0400 (Thu, 25 Sep 2008)
New Revision: 10561
Modified:
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
Log:
SortExpression evaluation
Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-09-25
14:47:04 UTC (rev 10560)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-09-25
15:29:56 UTC (rev 10561)
@@ -8,6 +8,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
import javax.el.ELContext;
import javax.el.ELException;
@@ -365,8 +366,54 @@
new Class[] { Object.class });
((HtmlColumn) component).setFilterMethod(mexpr);
}
+ // Set SortExpression attribute especially for scrollable data table
+ if (_sortExpression != null) {
+ //((HtmlColumn) component).setSortExpression(createSortExpression());
+ String ex = createSortExpression();
+ ValueExpression vexpr = getFacesContext().getApplication()
+ .getExpressionFactory().createValueExpression(pageContext.getELContext(),
+ ex, _sortExpression.getExpectedType());
+ component.setValueExpression("sortExpression", vexpr);
+ }
+
+
}
+
+ /**
+ * Evaluates expression string for SortExpression attribute using resolved vars nodes.
+ * @return
+ */
+ private String createSortExpression() {
+ String expr = null;
+ try {
+ String orig = _sortExpression.getExpressionString()
+ .replaceAll("[\\#\\{\\}]", "").trim();
+ String varReplacement = __value.getExpressionString()
+ .replaceAll("[#{}]", "")+ "[" + index +
"]";
+ if (itemId.equals(orig)) {
+ expr = varReplacement;
+ } else {
+ String indexReplacement = String.valueOf(index);
+ String varPatter1 = "^" + itemId + "([\\.\\[\\]])";
+ String varPatter2 = "([\\s\"$%#\\^|]+)" + itemId
+ + "([\\.\\[\\]])";
+ String indexPattern = "([\\[\\]]{1})" + indexId
+ + "([\\[\\]]{1})";
+
+ orig = orig.replaceAll(varPatter1, varReplacement + "$1");
+ orig = orig
+ .replaceAll(varPatter2, "$1" + varReplacement + "$2");
+ orig = orig.replaceAll(indexPattern, "$1" + indexReplacement
+ + "$2");
+ expr = orig;
+ }
+ } catch (Exception e) {
+ }
+ expr = "#{" + expr + "}";
+ return expr;
+ }
+
/**
* Creates value expression to be out into column
*
Show replies by date