* javax.faces.component.UIComponent)
*/
public void apply(FacesContext facesContext, UIComponent parent) throws IOException, FacesException,
FaceletException, ELException
{
FaceletCompositionContext myFaceletContext = null;
boolean faceletCompositionContextInitialized = false;
boolean recordUniqueIds = false;
myFaceletContext = FaceletCompositionContext.getCurrentInstance(facesContext);
if (myFaceletContext == null)
{
myFaceletContext = new FaceletCompositionContextImpl(_factory, facesContext);
myFaceletContext.init(facesContext);
faceletCompositionContextInitialized = true;
if (_encodingHandler && !myFaceletContext.isBuildingViewMetadata()
&& MyfacesConfig.getCurrentInstance(
facesContext.getExternalContext()).isViewUniqueIdsCacheEnabled() &&
_refreshPeriod <= 0)
{
List<String> uniqueIdList = ((EncodingHandler)_root).getUniqueIdList();
if (uniqueIdList == null)
{
myFaceletContext.initUniqueIdRecording();
recordUniqueIds = true;
}
else
{
myFaceletContext.setUniqueIdsIterator(uniqueIdList.iterator());
}
}
if (parent instanceof UIViewRoot)
{
ComponentSupport.setCachedFacesContext((UIViewRoot)parent, facesContext);
}
}
DefaultFaceletContext ctx = new DefaultFaceletContext(facesContext, this, myFaceletContext);
//Set FACELET_CONTEXT_KEY on FacesContext attribute map, to
//reflect the current facelet context instance
FaceletContext oldCtx = (FaceletContext)
facesContext.getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctx);
ctx.pushPageContext(new PageContextImpl());
try
{
// push the parent as a UniqueIdVendor to the stack here,
// if there is no UniqueIdVendor on the stack yet
boolean pushedUniqueIdVendor = false;
if (parent instanceof UniqueIdVendor
&& ctx.getFaceletCompositionContext().getUniqueIdVendorFromStack() == null)
{
ctx.getFaceletCompositionContext().pushUniqueIdVendorToStack((UniqueIdVendor) parent);
pushedUniqueIdVendor = true;
}
this.refresh(parent);
myFaceletContext.markForDeletion(parent);
_root.apply(ctx, parent);
if (faceletCompositionContextInitialized &&
parent instanceof UIViewRoot)
{
UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
if (metadataFacet != null)
{
// Ensure metadata facet is removed from deletion, so if by some reason
// is not refreshed, its content will not be removed from the component tree.
// This behavior is preferred, even if the spec suggest to include it using
// a trick with the template client.
myFaceletContext.removeComponentForDeletion(metadataFacet);
}
if (myFaceletContext.isRefreshingTransientBuild())
{
myFaceletContext.finalizeRelocatableResourcesForDeletion((UIViewRoot) parent);
}
}
myFaceletContext.finalizeForDeletion(parent);
this.markApplied(parent);
// remove the UniqueIdVendor from the stack again
if (pushedUniqueIdVendor)
{
ctx.getFaceletCompositionContext().popUniqueIdVendorToStack();
}
}
finally
{
ctx.popPageContext();
if (faceletCompositionContextInitialized)
{
if (parent instanceof UIViewRoot)
{
ComponentSupport.setCachedFacesContext((UIViewRoot)parent, null);
}
myFaceletContext.release(facesContext);
List<String> uniqueIdList = ((EncodingHandler)_root).getUniqueIdList();
if (recordUniqueIds && uniqueIdList == null)
{
uniqueIdList = Collections.unmodifiableList(
myFaceletContext.getUniqueIdList());
((EncodingHandler)_root).setUniqueIdList(uniqueIdList);
}
}
if (oldCtx != null)