You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2015/04/23 17:36:50 UTC

svn commit: r1675638 - in /myfaces/tobago/branches/tobago-3.0.x: ./ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ tobago-core/src/main/java/org/apache/myfaces/...

Author: lofwyr
Date: Thu Apr 23 15:36:48 2015
New Revision: 1675638

URL: http://svn.apache.org/r1675638
Log:
Merged from trunk
TOBAGO-1457: Sheet sort may be performed twice and possible NPE when using method binding for sorting [from revision 1675636]

Modified:
    myfaces/tobago/branches/tobago-3.0.x/   (props changed)
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java   (contents, props changed)

Propchange: myfaces/tobago/branches/tobago-3.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 23 15:36:48 2015
@@ -1,3 +1,3 @@
 /myfaces/tobago/branches/tobago-1.5.x:1356585,1357124
 /myfaces/tobago/branches/tobago-tree-table:1226794-1341423
-/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1657180,1657269,1657276,1657279,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665569,1666464,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589
+/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1657180,1657269,1657276,1657279,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665569,1666464,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589,1675636

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java?rev=1675638&r1=1675637&r2=1675638&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java Thu Apr 23 15:36:48 2015
@@ -55,14 +55,18 @@ import javax.faces.component.UIComponent
 import javax.faces.component.UINamingContainer;
 import javax.faces.context.FacesContext;
 import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
 import javax.faces.event.FacesEvent;
+import javax.faces.event.ListenerFor;
 import javax.faces.event.PhaseId;
+import javax.faces.event.PreRenderComponentEvent;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+@ListenerFor(systemEventClass = PreRenderComponentEvent.class)
 public abstract class AbstractUISheet extends AbstractUIData
     implements SheetStateChangeSource2, SortActionSource2, OnComponentPopulated,
     LayoutContainer, LayoutComponent, SupportsCss, SupportsRenderedPartially {
@@ -112,18 +116,6 @@ public abstract class AbstractUISheet ex
       }
     }
 
-    final MethodExpression expression = getSortActionListenerExpression();
-    if (expression != null) {
-      try {
-        FacesEvent facesEvent = new SortActionEvent(this, null);
-        expression.invoke(facesContext.getELContext(), new Object[]{facesEvent});
-      } catch (Exception e) {
-        LOG.warn("Initial sorting not possible!", e);
-      }
-    } else {
-      new Sorter().perform(this);
-    }
-
     super.encodeBegin(facesContext);
   }
 
@@ -455,12 +447,35 @@ public abstract class AbstractUISheet ex
       }
     } else if (facesEvent instanceof SortActionEvent) {
       getSheetState(getFacesContext()).updateSortState((SortActionEvent) facesEvent);
+      sort(getFacesContext(), (SortActionEvent) facesEvent);
+    }
+  }
+
+  public void processEvent(ComponentSystemEvent event) {
+    super.processEvent(event);
+    if (event instanceof PreRenderComponentEvent) {
+      sort(getFacesContext(), null);
+    }
+  }
+
+  protected void sort(FacesContext facesContext, SortActionEvent event) {
+    final SheetState sheetState = getSheetState(getFacesContext());
+    if (sheetState.isToBeSorted()) {
       final MethodExpression expression = getSortActionListenerExpression();
       if (expression != null) {
-        expression.invoke(getFacesContext().getELContext(), new Object[]{facesEvent});
+        try {
+          if (event == null) {
+            event =
+                new SortActionEvent(this, (UIColumn) findComponent(getSheetState(facesContext).getSortedColumnId()));
+          }
+          expression.invoke(facesContext.getELContext(), new Object[]{event});
+        } catch (Exception e) {
+          LOG.warn("Sorting not possible!", e);
+        }
       } else {
-        new Sorter().perform((SortActionEvent) facesEvent);
+        new Sorter().perform(this);
       }
+      sheetState.setToBeSorted(false);
     }
   }
 

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java?rev=1675638&r1=1675637&r2=1675638&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java Thu Apr 23 15:36:48 2015
@@ -458,6 +458,13 @@ public final class StringUtils {
   }
 
   /**
+   * Basically taken from commons-lang
+   */
+  public static boolean notEquals(String a, String b) {
+    return a == null ? b != null : !a.equals(b);
+  }
+
+  /**
    * Checks if the String starts like a url, e.g. http: or xyz:
    */
   public static boolean isUrl(final String link) {

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java?rev=1675638&r1=1675637&r2=1675638&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java Thu Apr 23 15:36:48 2015
@@ -40,6 +40,7 @@ public class SheetState implements Seria
   private int first;
   private String sortedColumnId;
   private boolean ascending;
+  private boolean toBeSorted;
   private String columnWidths;
   private List<Integer> selectedRows;
   private Integer[] scrollPosition;
@@ -54,6 +55,7 @@ public class SheetState implements Seria
     first = -1;
     sortedColumnId = null;
     ascending = true;
+    toBeSorted = false;
     columnWidths = null;
     resetSelected();
     if (expandedState != null) {
@@ -83,7 +85,10 @@ public class SheetState implements Seria
   }
 
   public void setSortedColumnId(final String sortedColumnId) {
-    this.sortedColumnId = sortedColumnId;
+    if (StringUtils.notEquals(this.sortedColumnId, sortedColumnId)) {
+      this.sortedColumnId = sortedColumnId;
+      toBeSorted = true;
+    }
   }
 
   public boolean isAscending() {
@@ -91,7 +96,10 @@ public class SheetState implements Seria
   }
 
   public void setAscending(final boolean ascending) {
-    this.ascending = ascending;
+    if (this.ascending != ascending) {
+      this.ascending = ascending;
+      toBeSorted = true;
+    }
   }
 
   public String getColumnWidths() {
@@ -115,10 +123,10 @@ public class SheetState implements Seria
     final UIColumn actualColumn = sortEvent.getColumn();
 
     if (actualColumn.getId().equals(sortedColumnId)) {
-      ascending = !ascending;
+      setAscending(!isAscending());
     } else {
-      ascending = true;
-      sortedColumnId = actualColumn.getId();
+      setAscending(true);
+      setSortedColumnId(actualColumn.getId());
     }
   }
 
@@ -152,6 +160,14 @@ public class SheetState implements Seria
     this.selectedState = selectedState;
   }
 
+  public boolean isToBeSorted() {
+    return toBeSorted;
+  }
+
+  public void setToBeSorted(boolean toBeSorted) {
+    this.toBeSorted = toBeSorted;
+  }
+
   /**
    * @deprecated since 2.0.0
    */

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=1675638&r1=1675637&r2=1675638&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java Thu Apr 23 15:36:48 2015
@@ -518,6 +518,8 @@ public class TobagoDemoController implem
     final SolarObject sun = list.remove(0);
     final String columnId = sheetState.getSortedColumnId();
 
+    LOG.info("Sorting column '{}'", columnId);
+
     Comparator<SolarObject> comparator = null;
 
     if ("name".equals(columnId)) {

Propchange: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 23 15:36:48 2015
@@ -1,3 +1,3 @@
 /myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java:1356585,1357124
 /myfaces/tobago/branches/tobago-tree-table/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java:1226794-1341423
-/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1590288,1641775,1666464
+/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1590288,1641775,1666464,1675636