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 2012/12/21 16:41:52 UTC
svn commit: r1424976 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets:
FaceletCompositionContext.java impl/DefaultFacelet.java
impl/FaceletCompositionContextImpl.java
tag/jsf/ComponentTagHandlerDelegate.java
Author: lu4242
Date: Fri Dec 21 15:41:52 2012
New Revision: 1424976
URL: http://svn.apache.org/viewvc?rev=1424976&view=rev
Log:
MYFACES-3659 Conditional include of scripts and stylesheets (Thanks to Dennis Hoersch for provide this patch)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java?rev=1424976&r1=1424975&r2=1424976&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java Fri Dec 21 15:41:52 2012
@@ -23,6 +23,7 @@ import java.util.List;
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 @@ abstract public class FaceletComposition
}
/**
+ * 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
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java?rev=1424976&r1=1424975&r2=1424976&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java Fri Dec 21 15:41:52 2012
@@ -190,6 +190,10 @@ final class DefaultFacelet extends Abstr
// a trick with the template client.
myFaceletContext.removeComponentForDeletion(metadataFacet);
}
+ if (myFaceletContext.isRefreshingTransientBuild())
+ {
+ myFaceletContext.finalizeRelocatableResourcesForDeletion((UIViewRoot) parent);
+ }
}
myFaceletContext.finalizeForDeletion(parent);
this.markApplied(parent);
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java?rev=1424976&r1=1424975&r2=1424976&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java Fri Dec 21 15:41:52 2012
@@ -26,6 +26,7 @@ import java.util.List;
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 class FaceletCompositionContextIm
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 @@ public class FaceletCompositionContextIm
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 class FaceletCompositionContextIm
_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 class FaceletCompositionContextIm
_uniqueIdVendorStack = null;
_validationGroupsStack = null;
_componentsMarkedForDeletion = null;
+ _relocatableResourceForDeletion = null;
_sectionUniqueIdCounter = null;
_sectionUniqueNormalIdCounter = null;
_sectionUniqueMetadataIdCounter = null;
@@ -911,6 +918,61 @@ public class FaceletCompositionContextIm
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++;
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=1424976&r1=1424975&r2=1424976&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 Fri Dec 21 15:41:52 2012
@@ -226,7 +226,16 @@ public class ComponentTagHandlerDelegate
{
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 class ComponentTagHandlerDelegate
// hook method
_delegate.onComponentCreated(ctx, c, parent);
+
+ if (mctx.isRefreshingTransientBuild() && _relocatableResourceHandler != null)
+ {
+ mctx.markRelocatableResourceForDeletion(c);
+ }
}
c.pushComponentToEL(facesContext, c);