You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2006/12/28 21:06:22 UTC

svn commit: r490815 - in /incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model: ChildPropertyTreeModel.java SortableModel.java

Author: awiner
Date: Thu Dec 28 13:06:21 2006
New Revision: 490815

URL: http://svn.apache.org/viewvc?view=rev&rev=490815
Log:
ADFFACES-342: ChildPropertyTreeModel and SortableModel will throw NPE if used outside of the JSF lifecycle

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.java
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.java?view=diff&rev=490815&r1=490814&r2=490815
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.java Thu Dec 28 13:06:21 2006
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import javax.faces.context.FacesContext;
+import javax.faces.el.PropertyResolver;
 
 /**
  * Creates a TreeModel from a List of beans.
@@ -312,9 +313,8 @@
     if (prop == null)
       return null;
     
-    FacesContext context = FacesContext.getCurrentInstance();
-    return 
-      context.getApplication().getPropertyResolver().getValue(parentData, prop);
+    PropertyResolver resolver = SortableModel.__getPropertyResolver();
+    return resolver.getValue(parentData, prop);
   }
 
   /**

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java?view=diff&rev=490815&r1=490814&r2=490815
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java Thu Dec 28 13:06:21 2006
@@ -19,6 +19,8 @@
 import java.util.Comparator;
 import java.util.List;
 
+import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.context.FacesContext;
 import javax.faces.el.PropertyResolver;
 import javax.faces.model.DataModel;
@@ -145,8 +147,7 @@
       Object data = _model.getRowData();
       try
       {
-        FacesContext context = FacesContext.getCurrentInstance();
-        PropertyResolver resolver = context.getApplication().getPropertyResolver();
+        PropertyResolver resolver = __getPropertyResolver();
         Object propertyValue = resolver.getValue(data, property);
 
         // when the value is null, we don't know if we can sort it.
@@ -246,9 +247,8 @@
     // Make sure the model has that row 0! (It could be empty.)
     if (_model.isRowAvailable())
     {
-      FacesContext context = FacesContext.getCurrentInstance();
       Comparator<Integer> comp =
-        new Comp(context. getApplication().getPropertyResolver(), property);
+        new Comp(__getPropertyResolver(), property);
       if (!isAscending)
         comp = new Inverter<Integer>(comp);
 
@@ -386,6 +386,22 @@
     }
 
     private final Comparator<T> _comp;
+  }
+
+  static PropertyResolver __getPropertyResolver()
+  {
+    // First try the FacesContext, which is a faster way to
+    // get the PropertyResolver (and the 99.9% scenario)
+    FacesContext context = FacesContext.getCurrentInstance();
+    if (context != null)
+      return context.getApplication().getPropertyResolver();
+    
+    // If that fails, then we're likely outside of the JSF lifecycle.
+    // Look to the ApplicationFactory.
+    ApplicationFactory factory = (ApplicationFactory)
+      FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+    return factory.getApplication().getPropertyResolver();
+    
   }
 
   private SortCriterion _sortCriterion = null;