You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/11/06 03:41:07 UTC
svn commit: r1539216 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf:
ComponentRelocatableResourceHandler.java ComponentTagHandlerDelegate.java
html/_HtmlOutputStylesheet.java
Author: lu4242
Date: Wed Nov 6 02:41:07 2013
New Revision: 1539216
URL: http://svn.apache.org/r1539216
Log:
MYFACES-3819 - Allow override resource components using a tag handler
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRelocatableResourceHandler.java
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/_HtmlOutputStylesheet.java
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRelocatableResourceHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRelocatableResourceHandler.java?rev=1539216&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRelocatableResourceHandler.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRelocatableResourceHandler.java Wed Nov 6 02:41:07 2013
@@ -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.view.facelets.tag.jsf;
+
+import java.util.Iterator;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.view.facelets.FaceletContext;
+
+/**
+ * This class is used in cases where alternate implementations of h:outputScript and h:outputStylesheet
+ * components are used overriding a tag handler and providing a new tag name, but preserving the componentType
+ * and rendererType. In those components, the relocation hack is done, but it is necessary to provide the
+ * additional code from the implementation.
+ */
+public class ComponentRelocatableResourceHandler implements RelocatableResourceHandler
+{
+ public static final ComponentRelocatableResourceHandler INSTANCE = new ComponentRelocatableResourceHandler();
+
+ public UIComponent findChildByTagId(FaceletContext ctx, UIComponent parent,
+ String id)
+ {
+ UIComponent c = null;
+ UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
+ if (root.getFacetCount() > 0)
+ {
+ Iterator<UIComponent> itr = root.getFacets().values().iterator();
+ while (itr.hasNext() && c == null)
+ {
+ UIComponent facet = itr.next();
+ c = ComponentSupport.findChildByTagId(facet, id);
+ }
+ }
+ return c;
+ }
+
+}
\ No newline at end of file
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=1539216&r1=1539215&r2=1539216&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java Wed Nov 6 02:41:07 2013
@@ -35,6 +35,7 @@ import javax.faces.application.ProjectSt
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
import javax.faces.component.UniqueIdVendor;
import javax.faces.component.ValueHolder;
import javax.faces.component.behavior.ClientBehaviorHolder;
@@ -63,6 +64,7 @@ import org.apache.myfaces.view.facelets.
import org.apache.myfaces.view.facelets.FaceletDynamicComponentRefreshTransientBuildEvent;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageBase;
+import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
import org.apache.myfaces.view.facelets.tag.MetaRulesetImpl;
import org.apache.myfaces.view.facelets.tag.jsf.core.AjaxHandler;
import org.apache.myfaces.view.facelets.tag.jsf.core.FacetHandler;
@@ -100,6 +102,10 @@ public class ComponentTagHandlerDelegate
public ComponentTagHandlerDelegate(ComponentHandler delegate)
{
_delegate = delegate;
+ ComponentConfig delegateComponentConfig = delegate.getComponentConfig();
+ _componentType = delegateComponentConfig.getComponentType();
+ _rendererType = delegateComponentConfig.getRendererType();
+ _id = delegate.getTagAttribute("id");
ComponentHandler handler = _delegate;
boolean found = false;
@@ -151,13 +157,19 @@ public class ComponentTagHandlerDelegate
}
else
{
- _relocatableResourceHandler = null;
+ // Check if the component is a relocatable component done overriding the tag handler
+ if (_componentType != null && _rendererType != null &&
+ (_rendererType.equals("javax.faces.resource.Script") ||
+ _rendererType.equals("javax.faces.resource.Stylesheet")) &&
+ _componentType.equals(UIOutput.COMPONENT_TYPE))
+ {
+ _relocatableResourceHandler = ComponentRelocatableResourceHandler.INSTANCE;
+ }
+ else
+ {
+ _relocatableResourceHandler = null;
+ }
}
-
- ComponentConfig delegateComponentConfig = delegate.getComponentConfig();
- _componentType = delegateComponentConfig.getComponentType();
- _rendererType = delegateComponentConfig.getRendererType();
- _id = delegate.getTagAttribute("id");
}
/**
@@ -325,6 +337,18 @@ public class ComponentTagHandlerDelegate
// hook method
_delegate.onComponentCreated(ctx, c, parent);
+ if (_relocatableResourceHandler != null &&
+ _relocatableResourceHandler instanceof ComponentRelocatableResourceHandler)
+ {
+ UIComponent parentCompositeComponent
+ = mctx.getCompositeComponentFromStack();
+ if (parentCompositeComponent != null)
+ {
+ c.getAttributes().put(CompositeComponentELUtils.LOCATION_KEY,
+ parentCompositeComponent.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY));
+ }
+ }
+
if (mctx.isRefreshingTransientBuild() && _relocatableResourceHandler != null)
{
mctx.markRelocatableResourceForDeletion(c);
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/_HtmlOutputStylesheet.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/_HtmlOutputStylesheet.java?rev=1539216&r1=1539215&r2=1539216&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/_HtmlOutputStylesheet.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/_HtmlOutputStylesheet.java Wed Nov 6 02:41:07 2013
@@ -34,7 +34,7 @@ import org.apache.myfaces.buildtools.mav
*/
@JSFComponent(
configExcluded=true,
- defaultRendererType="javax.faces.resource.Script")
+ defaultRendererType="javax.faces.resource.Stylesheet")
abstract class _HtmlOutputStylesheet extends UIOutput
{
/**