myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcrawf...@apache.org
Subject svn commit: r891530 - in /myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/application/ java/org/apache/myfaces/trinidadinternal/renderkit/core/ xrts/org/apache/myfaces/trinidadinternal/resource/
Date Thu, 17 Dec 2009 04:09:30 GMT
Author: gcrawford
Date: Thu Dec 17 04:09:29 2009
New Revision: 891530

URL: http://svn.apache.org/viewvc?rev=891530&view=rev
Log:
TRINIDAD-1639 NPE thrown when ResponseStateManagerImpl returns a null state - on partialSubmit
using a JSF 2.0 Ajax APIs...

Modified:
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java?rev=891530&r1=891529&r2=891530&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
Thu Dec 17 04:09:29 2009
@@ -112,6 +112,22 @@
     return _delegate;
   }
 
+  @Override
+  public String getViewState(FacesContext context)
+  {
+    Object state = saveView(context);
+    
+    if (state != null)
+    {
+      return context.getRenderKit().getResponseStateManager().getViewState(context,state);
+    }
+    else
+    {
+      return null;
+    }
+
+  }
+
   @SuppressWarnings("deprecation")
   @Override
   public Object saveView(FacesContext context)
@@ -138,14 +154,7 @@
     }
     
     String viewId = context.getViewRoot().getViewId();
-    ViewDeclarationLanguage vdl =  context.getApplication().getViewHandler().
-                                                    getViewDeclarationLanguage(context, viewId);
-    StateManagementStrategy sms = null;
-    
-    if (vdl != null) 
-    {
-      sms = vdl.getStateManagementStrategy(context, viewId);
-    }    
+    StateManagementStrategy sms = _getStateManagementStrategy(context, viewId);
     
     if (sms != null) 
     {      
@@ -498,14 +507,7 @@
         return root;
       }
 
-      ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().
-                                                        getViewDeclarationLanguage(context,
viewId);    
-      StateManagementStrategy sms = null;
-      
-      if (vdl != null) 
-      {
-        sms = vdl.getStateManagementStrategy(context, viewId);
-      }
+      StateManagementStrategy sms = _getStateManagementStrategy(context, viewId);
       
       if (sms!= null) 
       {
@@ -536,14 +538,8 @@
     }
     else
     {
-      ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().
-                                                       getViewDeclarationLanguage(context,
viewId);    
-      StateManagementStrategy sms = null;
-      
-      if (vdl != null) 
-      {
-        sms = vdl.getStateManagementStrategy(context, viewId);
-      }
+
+      StateManagementStrategy sms = _getStateManagementStrategy(context, viewId);
       
       if (sms!= null) 
       {
@@ -915,6 +911,20 @@
     context.getExternalContext().getRequestMap().put(_CACHED_VIEW_STATE,
                                                      state);
   }
+  
+  private StateManagementStrategy _getStateManagementStrategy(FacesContext context, String
viewId)
+  {
+    ViewDeclarationLanguage vdl =  context.getApplication().getViewHandler().
+                                                    getViewDeclarationLanguage(context, viewId);
+    if (vdl != null) 
+    {
+      return vdl.getStateManagementStrategy(context, viewId);
+    }    
+    else
+    {
+      return null;
+    }
+  }
 
   private static final class ViewRootState
   {

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java?rev=891530&r1=891529&r2=891530&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
Thu Dec 17 04:09:29 2009
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,36 +18,34 @@
  */
 package org.apache.myfaces.trinidadinternal.renderkit.core;
 
-import javax.faces.application.StateManager;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.ResponseStateManager;
-
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
 import java.io.OptionalDataException;
 import java.io.StringReader;
-import java.io.BufferedReader;
 import java.io.StringWriter;
-import java.io.BufferedWriter;
 
-
-import java.io.ObjectStreamClass;
-
-import java.util.zip.GZIPOutputStream;
+import java.util.Map;
 import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
 
-import java.util.Map;
+import javax.faces.FacesException;
+import javax.faces.application.StateManager;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.ResponseStateManager;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
 import org.apache.myfaces.trinidad.util.Base64InputStream;
 import org.apache.myfaces.trinidad.util.Base64OutputStream;
 import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
 import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
 
+
 /**
  * ResponseStateManager implementation for the Core RenderKit.
  * <p>
@@ -56,21 +54,21 @@
 {
 
   @Override
-  public Object getState(FacesContext context, String viewId) 
+  public Object getState(FacesContext context, String viewId)
   {
-    // TODO see doc in StateManagerImpl.restoreView 
+    // TODO see doc in StateManagerImpl.restoreView
     // (search for StateManagerImpl.RESPONSE_STATE_MANAGER_STATE_KEY) to see doc
     // about what's going on here
     Object state = context.getExternalContext().getRequestMap().get(
                                               StateManagerImpl.RESPONSE_STATE_MANAGER_STATE_KEY);
-    
+
     if (state != null)
       return state;
-    else 
+    else
       return super.getState(context, viewId);
   }
-  
-  
+
+
   /**
    * Name of the form field that encodes the UI state.
    */
@@ -161,6 +159,56 @@
     return view[1];
   }
 
+  @Override
+  public String getViewState(FacesContext context, Object state)
+  {
+    StateManager.SerializedView serializedView = _getSerializedView(context, state);
+    try
+    {
+      return encodeSerializedViewAsString(serializedView);
+    }
+    catch (IOException e)
+    {
+      throw new FacesException();
+    }
+  }
+
+  private StateManager.SerializedView _getSerializedView(FacesContext context, Object state)
+  {
+
+    StateManager.SerializedView view;
+    if (state instanceof StateManager.SerializedView)
+    {
+      view = (StateManager.SerializedView) state;
+    }
+    else
+    {
+      if (state instanceof Object[])
+      {
+        Object[] stateArray = (Object[]) state;
+
+        // in theory the state should be a black box, but the RI makes assumptions
+        // that the state is an array of length 2
+        if (stateArray.length == 2)
+        {
+          StateManager stateManager =
+            context.getApplication().getStateManager();
+          view =
+              stateManager.new SerializedView(stateArray[0], stateArray[1]);
+        }
+        else
+        {
+          throw new IllegalArgumentException(_LOG.getMessage("UNEXPECTED_STATE"));
+        }
+      }
+      else
+      {
+        throw new IllegalArgumentException(_LOG.getMessage("UNEXPECTED_STATE"));
+      }
+    }
+
+    return view;
+  }
 
   /**
    * Restore the serialized view from the incoming request.
@@ -171,9 +219,9 @@
   private Object[] _restoreSerializedView(
      FacesContext context)
   {
-    Map<String, Object> requestMap = 
+    Map<String, Object> requestMap =
       context.getExternalContext().getRequestMap();
-    
+
     Object[] view = (Object[]) requestMap.get(_CACHED_SERIALIZED_VIEW);
     if (view == null)
     {
@@ -245,6 +293,8 @@
   }
 
 
+
+
   /* Test code for dumping out the page's state
   static private void _dump(Object o)
   {

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts?rev=891530&r1=891529&r2=891530&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts
Thu Dec 17 04:09:29 2009
@@ -1076,4 +1076,7 @@
 <!-- INVALID_LOCALE_VARIANT_HAS_SLASH  -->
 <resource key="INVALID_LOCALE_VARIANT_HAS_SLASH">Invalid variant for Locale identifier
{0} - cannot contain slashes to avoid XSS attack. Will use empty string for variant.</resource>
 
+<!-- UNEXPECTED_STATE -->
+<resource key="UNEXPECTED_STATE">IState must be an instance of StateManager.SerializedView
or an Object array of length 2.</resource>
+
 </resources>



Mime
View raw message