You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/06/22 14:35:12 UTC

[myfaces] branch master updated: MYFACES-4227

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new bcd1c40  MYFACES-4227
bcd1c40 is described below

commit bcd1c401b8e28b61e5568b675d69ae2ed3ba755a
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Fri Jun 22 16:35:06 2018 +0200

    MYFACES-4227
---
 .../myfaces/application/ApplicationImpl.java       |  5 +-
 .../myfaces/component/ComponentResourceUtils.java  | 54 ++++++++++++++++++++++
 .../myfaces/renderkit/html/HtmlScriptRenderer.java | 29 +-----------
 .../renderkit/html/HtmlStylesheetRenderer.java     | 29 ++----------
 4 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java b/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
index de30135..3e5c82e 100755
--- a/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
@@ -102,6 +102,7 @@ import org.apache.myfaces.cdi.behavior.FacesBehaviorCDIWrapper;
 import org.apache.myfaces.cdi.behavior.FacesClientBehaviorCDIWrapper;
 import org.apache.myfaces.cdi.converter.FacesConverterCDIWrapper;
 import org.apache.myfaces.cdi.validator.FacesValidatorCDIWrapper;
+import org.apache.myfaces.component.ComponentResourceUtils;
 import org.apache.myfaces.component.search.AllSearchKeywordResolver;
 import org.apache.myfaces.component.search.ChildSearchKeywordResolver;
 import org.apache.myfaces.component.search.CompositeComponentParentSearchKeywordResolver;
@@ -2604,13 +2605,13 @@ public class ApplicationImpl extends Application
                                       context.getELContext(), target).toString(context.getELContext());
                 // If target is non-null, store it under the key "target".
                 attributes.put("target", target);
-                context.getViewRoot().addComponentResource(context, output, target);
+                ComponentResourceUtils.addComponentResource(context, output, target);
             }
             else
             {
                 // Otherwise, if target is null, call UIViewRoot.addComponentResource(javax.faces.context.FacesContext,
                 // javax.faces.component.UIComponent), passing the UIOutput instance as the second argument.
-                context.getViewRoot().addComponentResource(context, output);
+                ComponentResourceUtils.addComponentResource(context, output);
             }
         }
     }
diff --git a/impl/src/main/java/org/apache/myfaces/component/ComponentResourceUtils.java b/impl/src/main/java/org/apache/myfaces/component/ComponentResourceUtils.java
new file mode 100644
index 0000000..86b5c30
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/component/ComponentResourceUtils.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.myfaces.component;
+
+import javax.faces.application.StateManager;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import org.apache.myfaces.context.RequestViewContext;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+
+public class ComponentResourceUtils
+{
+    public static void addComponentResource(FacesContext context, UIComponent componentResource)
+    {
+        addComponentResource(context, componentResource, null);
+    }
+
+    public static void addComponentResource(FacesContext context, UIComponent componentResource, String target)
+    {
+        if (context.getPartialViewContext().isAjaxRequest() )
+        {
+            boolean isBuildingInitialState = context.getAttributes().
+                containsKey(StateManager.IS_BUILDING_INITIAL_STATE);
+
+            // The next condition takes into account the current request is an ajax request. 
+            boolean isPostAddToViewEventAfterBuildInitialState = !isBuildingInitialState ||
+                (isBuildingInitialState && FaceletViewDeclarationLanguage.isRefreshingTransientBuild(context));
+
+            if (isPostAddToViewEventAfterBuildInitialState)
+            {
+                RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(context);
+                requestViewContext.setRenderTarget("head", true, componentResource);
+            }
+        }
+        
+        context.getViewRoot().addComponentResource(context, componentResource, target);
+    }
+}
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
index 80f0d45..cd385b4 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
@@ -38,12 +38,11 @@ import javax.faces.render.Renderer;
 import javax.faces.view.Location;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
-import org.apache.myfaces.context.RequestViewContext;
+import org.apache.myfaces.component.ComponentResourceUtils;
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.HTML;
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
-import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
 import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 
@@ -60,8 +59,6 @@ public class HtmlScriptRenderer extends Renderer implements ComponentSystemEvent
 {
     private static final Logger log = Logger.getLogger(HtmlScriptRenderer.class.getName());
 
-    private static final String IS_BUILDING_INITIAL_STATE = "javax.faces.IS_BUILDING_INITIAL_STATE";
-
     @Override
     public void processEvent(ComponentSystemEvent event)
     {
@@ -86,33 +83,11 @@ public class HtmlScriptRenderer extends Renderer implements ComponentSystemEvent
                     }
                 }
 
-                // If this is an ajax request and the view is being refreshed and a PostAddToViewEvent
-                // was propagated to relocate this resource, means the header must be refreshed.
-                // Note ajax request does not occur on non postback requests.
-                
-                if (facesContext.getPartialViewContext().isAjaxRequest())
-                {
-                    boolean isBuildingInitialState = facesContext.getAttributes().
-                        containsKey(IS_BUILDING_INITIAL_STATE);
-                    // The next condition takes into account the current request is an ajax request. 
-                    boolean isPostAddToViewEventAfterBuildInitialState = 
-                        !isBuildingInitialState ||
-                        (isBuildingInitialState && 
-                                FaceletViewDeclarationLanguage.isRefreshingTransientBuild(facesContext));
-                    if (isPostAddToViewEventAfterBuildInitialState)
-                    {
-                        //!(component.getParent() instanceof ComponentResourceContainer)
-                        RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
-                        requestViewContext.setRenderTarget("head", true, component);
-                    }
-                }
-                facesContext.getViewRoot().addComponentResource(facesContext,
-                        component, target);
+                ComponentResourceUtils.addComponentResource(facesContext, component, target);
             }
         }
 
         if (event instanceof PreRenderViewEvent)
-
         {
             //TODO target check here
             UIComponent component = event.getComponent();
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
index cef7e94..ef4df0d 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
@@ -36,12 +36,11 @@ import javax.faces.render.Renderer;
 import javax.faces.view.Location;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
-import org.apache.myfaces.context.RequestViewContext;
+import org.apache.myfaces.component.ComponentResourceUtils;
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.HTML;
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
-import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
 import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 
@@ -62,9 +61,7 @@ public class HtmlStylesheetRenderer extends Renderer implements
     ComponentSystemEventListener
 {
     private static final Logger log = Logger.getLogger(HtmlStylesheetRenderer.class.getName());
-    
-    private static final String IS_BUILDING_INITIAL_STATE = "javax.faces.IS_BUILDING_INITIAL_STATE";
-    
+        
     @Override
     public void processEvent(ComponentSystemEvent event)
     {
@@ -85,28 +82,8 @@ public class HtmlStylesheetRenderer extends Renderer implements
                             ComponentSupport.getFindComponentExpression(facesContext, ccParent));
                 }
             }
-            // If this is an ajax request and the view is being refreshed and a PostAddToViewEvent
-            // was propagated to relocate this resource, means the header must be refreshed.
-            // Note ajax request does not occur on non postback requests.
 
-            if (facesContext.getPartialViewContext().isAjaxRequest() )
-            {
-                boolean isBuildingInitialState = facesContext.getAttributes().
-                    containsKey(IS_BUILDING_INITIAL_STATE);
-                // The next condition takes into account the current request is an ajax request. 
-                boolean isPostAddToViewEventAfterBuildInitialState = 
-                    !isBuildingInitialState ||
-                    (isBuildingInitialState && 
-                            FaceletViewDeclarationLanguage.isRefreshingTransientBuild(facesContext));
-                if (isPostAddToViewEventAfterBuildInitialState)
-                {
-                    //!(component.getParent() instanceof ComponentResourceContainer)
-                    RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
-                    requestViewContext.setRenderTarget("head", true, component);
-                }
-            }
-            facesContext.getViewRoot().addComponentResource(facesContext,
-                        component, "head");
+            ComponentResourceUtils.addComponentResource(facesContext, component, "head");
         }
     }