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 2007/05/06 14:49:48 UTC

svn commit: r535605 - in /myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago: component/ComponentUtil.java context/TransientStateHolder.java lifecycle/RenderResponseExecutor.java

Author: bommel
Date: Sun May  6 05:49:47 2007
New Revision: 535605

URL: http://svn.apache.org/viewvc?view=rev&rev=535605
Log:
(TOBAGO-379) Using optimized version of ComponentUtil.findPage

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/TransientStateHolder.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/lifecycle/RenderResponseExecutor.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?view=diff&rev=535605&r1=535604&r2=535605
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Sun May  6 05:49:47 2007
@@ -55,6 +55,7 @@
 import org.apache.myfaces.tobago.event.PopupActionListener;
 import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
 import org.apache.myfaces.tobago.util.RangeParser;
+import org.apache.myfaces.tobago.context.TransientStateHolder;
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
@@ -123,17 +124,19 @@
     return false;
   }
 
-  public static void clearPageCache(FacesContext context) {
-    context.getExternalContext().getRequestMap().put(UIPage.COMPONENT_TYPE, null);
-  }
-
   public static UIPage findPage(FacesContext context, UIComponent component) {
-    UIPage page = (UIPage) context.getExternalContext().getRequestMap().get(UIPage.COMPONENT_TYPE);
-    if (page == null) {
-      page = findPage(component);
-      context.getExternalContext().getRequestMap().put(UIPage.COMPONENT_TYPE, page);
+    javax.faces.component.UIViewRoot view = context.getViewRoot();
+    if (view != null) {
+      TransientStateHolder stateHolder = (TransientStateHolder) view.getAttributes().get(UIPage.COMPONENT_TYPE);
+      if (stateHolder == null || stateHolder.isEmpty()) {
+        UIPage page = findPage(component);
+        stateHolder = new TransientStateHolder(page);
+        context.getViewRoot().getAttributes().put(UIPage.COMPONENT_TYPE, stateHolder);
+      }
+      return (UIPage) stateHolder.get();
+    } else {
+      return findPage(component);
     }
-    return page;
   }
   public static UIPage findPage(UIComponent component) {
     while (component != null) {

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/TransientStateHolder.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/TransientStateHolder.java?view=auto&rev=535605
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/TransientStateHolder.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/TransientStateHolder.java Sun May  6 05:49:47 2007
@@ -0,0 +1,67 @@
+package org.apache.myfaces.tobago.context;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import java.io.Serializable;
+
+/*
+ * Date: May 3, 2007
+ * Time: 5:44:04 PM
+ */
+public class TransientStateHolder implements StateHolder, Serializable {
+  private static final long serialVersionUID = -5260593843885016768L;
+  private transient Object object;
+
+
+  public TransientStateHolder(Object object) {
+    this.object = object;
+  }
+
+  public Object saveState(FacesContext context) {
+     // do nothing
+    return null;
+  }
+
+  public void put(Object object) {
+    this.object = object;
+  }
+
+  public boolean isEmpty() {
+    return object == null;
+  }
+
+  public Object get() {
+    return object;
+  }
+
+  public void restoreState(FacesContext context, Object state) {
+    // do nothing
+  }
+
+
+  public boolean isTransient() {
+    return true;
+  }
+
+  public void setTransient(boolean newTransientValue) {
+     // do nothing
+  }
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/lifecycle/RenderResponseExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/lifecycle/RenderResponseExecutor.java?view=diff&rev=535605&r1=535604&r2=535605
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/lifecycle/RenderResponseExecutor.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/lifecycle/RenderResponseExecutor.java Sun May  6 05:49:47 2007
@@ -19,7 +19,6 @@
 
 import org.apache.myfaces.tobago.ajax.api.AjaxResponseRenderer;
 import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
-import org.apache.myfaces.tobago.component.ComponentUtil;
 
 import javax.faces.FacesException;
 import javax.faces.application.Application;
@@ -50,7 +49,6 @@
         throw new FacesException(e.getMessage(), e);
       }
     } else {
-      ComponentUtil.clearPageCache(facesContext);
       Application application = facesContext.getApplication();
       ViewHandler viewHandler = application.getViewHandler();