You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2011/10/04 14:51:06 UTC

svn commit: r1178770 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/ tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/

Author: bommel
Date: Tue Oct  4 12:51:05 2011
New Revision: 1178770

URL: http://svn.apache.org/viewvc?rev=1178770&view=rev
Log:
(TOBAGO-1024) NullPointerException in TreeStructureManager with MyFaces 2.0 (error in post back detection) 
only for myfaces


Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoResponseStateManager.java
    myfaces/tobago/trunk/tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/FacesVersion.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?rev=1178770&r1=1178769&r2=1178770&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Tue Oct  4 12:51:05 2011
@@ -149,7 +149,7 @@ public class TobagoRenderKit extends Ren
 
   @Override
   public ResponseStateManager getResponseStateManager() {
-    if (FacesVersion.supports12()) {
+    if (FacesVersion.supports12() && FacesVersion.isMyfaces()) {
       return getHtmlBasicRenderKit().getResponseStateManager();
     } else {
       return responseStateManager;

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoResponseStateManager.java?rev=1178770&r1=1178769&r2=1178770&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoResponseStateManager.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoResponseStateManager.java Tue Oct  4 12:51:05 2011
@@ -40,6 +40,15 @@ public class TobagoResponseStateManager 
   private static final String STATE_PARAM = "javax.faces.ViewState";
   private static final String VIEWID_PARAM = "jsf_viewid";
 
+  public Object getState(FacesContext context, String viewId) {
+    Object treeStructure = getTreeStructureToRestore(context, viewId);
+    Object componentStateToRestore = getComponentStateToRestore(context);
+    if (treeStructure != null && componentStateToRestore != null) {
+        return new Object[] {treeStructure, componentStateToRestore};
+    }
+    return null;
+  }
+
   public Object getTreeStructureToRestore(FacesContext facescontext, String viewId) {
     Map requestMap = facescontext.getExternalContext().getRequestParameterMap();
     Object requestViewId = requestMap.get(VIEWID_PARAM);

Modified: myfaces/tobago/trunk/tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/FacesVersion.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/FacesVersion.java?rev=1178770&r1=1178769&r2=1178770&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/FacesVersion.java (original)
+++ myfaces/tobago/trunk/tobago-jsf-compat/src/main/java/org/apache/myfaces/tobago/util/FacesVersion.java Tue Oct  4 12:51:05 2011
@@ -26,6 +26,8 @@ public enum FacesVersion {
   VERSION_20;
 
   private static FacesVersion currentVersion;
+  private static boolean mojarra;
+  private static boolean myfaces;
 
   static {
     try {
@@ -44,6 +46,29 @@ public enum FacesVersion {
     } catch (NoSuchMethodException e) {
       currentVersion = VERSION_11;
     }
+    mojarra = isAvailable("com.sun.faces.application.ApplicationImpl");
+    myfaces = isAvailable("org.apache.myfaces.application.ApplicationImpl");
+
+  }
+
+  private static boolean isAvailable(String className) {
+    try {
+      try {
+        Class.forName(className, false, Thread.currentThread().getContextClassLoader());
+        return true;
+      } catch (ClassNotFoundException e) {
+        // ignore
+        try {
+          Class.forName(className, false, FacesVersion.class.getClassLoader());
+          return true;
+        } catch (ClassNotFoundException e1) {
+          // ignore
+        }
+      }
+    } catch (Exception e) {
+      // ignore
+    }
+    return false;
   }
 
   /**
@@ -61,4 +86,12 @@ public enum FacesVersion {
   public static boolean supports20() {
     return currentVersion == VERSION_20;
   }
+
+  public static boolean isMojarra() {
+    return mojarra;
+  }
+
+  public static boolean isMyfaces() {
+    return myfaces;
+  }
 }