Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MYFACES-3659 Conditional include of scripts and stylesheets (Thanks t…

…o Dennis Hoersch for provide this patch)

git-svn-id: https://svn.apache.org/repos/asf/myfaces/core/trunk@1424976 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 9b9cb50194fe29f10d19b9fa65ddf469ab8a3c53 1 parent 01c4140
Leonardo Uribe authored
24 impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
View
@@ -23,6 +23,7 @@
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import javax.faces.component.UniqueIdVendor;
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
@@ -342,6 +343,29 @@ public void removeComponentForDeletion(UIComponent component)
}
/**
+ * Marks the given resource for deletion. Is to be used for relocatable
+ * components instead of {@link #markForDeletion(UIComponent)}.
+ *
+ * @since 2.0.17 2.1.11
+ * @param component
+ * UIComponent to finalize
+ */
+ public void markRelocatableResourceForDeletion(UIComponent component)
+ {
+ }
+
+ /**
+ * Used to clean up all unused relocatable components on the root component.
+ *
+ * @since 2.0.17 2.1.11
+ * @param component
+ * UIComponent to finalize (root component)
+ */
+ public void finalizeRelocatableResourcesForDeletion(UIViewRoot root)
+ {
+ }
+
+ /**
* Add a method expression as targeted for the provided composite component
*
* @since 2.0.3
4 impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
View
@@ -190,6 +190,10 @@ public void apply(FacesContext facesContext, UIComponent parent) throws IOExcept
// a trick with the template client.
myFaceletContext.removeComponentForDeletion(metadataFacet);
}
+ if (myFaceletContext.isRefreshingTransientBuild())
+ {
+ myFaceletContext.finalizeRelocatableResourcesForDeletion((UIViewRoot) parent);
+ }
}
myFaceletContext.finalizeForDeletion(parent);
this.markApplied(parent);
62 impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
View
@@ -26,6 +26,7 @@
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import javax.faces.component.UniqueIdVendor;
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
@@ -81,6 +82,8 @@
public static final String INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE
= "org.apache.myfaces.WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE";
+ private static final String JAVAX_FACES_LOCATION_PREFIX = "javax_faces_location_";
+
private FacesContext _facesContext;
private FaceletFactory _factory;
@@ -113,6 +116,8 @@
private List<Map<String, UIComponent>> _componentsMarkedForDeletion;
+ private Map<String, UIComponent> _relocatableResourceForDeletion;
+
private int _deletionLevel;
private Map<UIComponent, List<AttachedObjectHandler>> _attachedObjectHandlers;
@@ -147,6 +152,7 @@ public FaceletCompositionContextImpl(FaceletFactory factory, FacesContext facesC
_factory = factory;
_facesContext = facesContext;
_componentsMarkedForDeletion = new ArrayList<Map<String,UIComponent>>();
+ _relocatableResourceForDeletion = new HashMap<String, UIComponent>();
_deletionLevel = -1;
_sectionUniqueIdCounter = new SectionUniqueIdCounter();
//Cached at facelet view
@@ -237,6 +243,7 @@ public void release(FacesContext facesContext)
_uniqueIdVendorStack = null;
_validationGroupsStack = null;
_componentsMarkedForDeletion = null;
+ _relocatableResourceForDeletion = null;
_sectionUniqueIdCounter = null;
_sectionUniqueNormalIdCounter = null;
_sectionUniqueMetadataIdCounter = null;
@@ -911,6 +918,61 @@ else if (id == null
decreaseComponentLevelMarkedForDeletion();
}
+ @Override
+ public void markRelocatableResourceForDeletion(UIComponent component)
+ {
+ // The idea is keep track of the component resources that can be relocated
+ // to later check which resources were not refreshed and delete them.
+ String id = (String) component.getAttributes().get(ComponentSupport.MARK_CREATED);
+ if (id != null)
+ {
+ _relocatableResourceForDeletion.put(id, component);
+ }
+ }
+
+ @Override
+ public void finalizeRelocatableResourcesForDeletion(UIViewRoot root)
+ {
+ String id = null;
+ //Check facets
+ if (root.getFacetCount() > 0)
+ {
+ Map<String, UIComponent> facets = root.getFacets();
+ for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
+ {
+ UIComponent fc = itr.next();
+ // It is necessary to check only the facets that are used as holder for
+ // component resources. To do that, the best way is check the ones that
+ // has id starting with "javax_faces_location_"
+ if (fc.getId() != null && fc.getId().startsWith(JAVAX_FACES_LOCATION_PREFIX))
+ {
+ // Check all children with MARK_CREATED and if one is found, check if it was
+ // refreshed by the algorithm.
+ int childCount = fc.getChildCount();
+ if (childCount > 0)
+ {
+ for (int i = 0; i < childCount; i ++)
+ {
+ UIComponent child = fc.getChildren().get(i);
+ id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+ if (id != null && finalizeRelocatableResourcesForDeletion(id) == null)
+ {
+ fc.getChildren().remove(i);
+ i--;
+ childCount--;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private UIComponent finalizeRelocatableResourcesForDeletion(String id)
+ {
+ return _relocatableResourceForDeletion.remove(id);
+ }
+
public String startComponentUniqueIdSection()
{
_level++;
14 impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
View
@@ -226,7 +226,16 @@ public void apply(FaceletContext ctx, UIComponent parent) throws IOException
{
log.fine(_delegate.getTag() + " Component[" + id + "] Found, marking children for cleanup");
}
+
+ // The call for mctx.markForDeletion(c) is always necessary, because
+ // component resource relocation occur as an effect of PostAddToViewEvent,
+ // so at this point it is unknown if the component was relocated or not.
mctx.markForDeletion(c);
+
+ if (_relocatableResourceHandler != null)
+ {
+ mctx.markRelocatableResourceForDeletion(c);
+ }
}
else
{
@@ -285,6 +294,11 @@ public void apply(FaceletContext ctx, UIComponent parent) throws IOException
// hook method
_delegate.onComponentCreated(ctx, c, parent);
+
+ if (mctx.isRefreshingTransientBuild() && _relocatableResourceHandler != null)
+ {
+ mctx.markRelocatableResourceForDeletion(c);
+ }
}
c.pushComponentToEL(facesContext, c);
Please sign in to comment.
Something went wrong with that request. Please try again.