protected void applyCompositeComponentFacelet(FaceletContext faceletContext, UIComponent compositeComponentBase)
throws IOException
{
FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(faceletContext);
AbstractFaceletContext actx = (AbstractFaceletContext) faceletContext;
UIPanel compositeFacetPanel
= (UIPanel) compositeComponentBase.getFacets().get(UIComponent.COMPOSITE_FACET_NAME);
if (compositeFacetPanel == null)
{
compositeFacetPanel = (UIPanel)
faceletContext.getFacesContext().getApplication().createComponent(
faceletContext.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
compositeFacetPanel.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER,
Boolean.TRUE);
compositeComponentBase.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, compositeFacetPanel);
// Set an id to the created facet component, to prevent id generation and make
// partial state saving work without problem.
UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
if (uniqueIdVendor == null)
{
uniqueIdVendor = ComponentSupport.getViewRoot(faceletContext, compositeComponentBase);
}
if (uniqueIdVendor != null)
{
// UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
// and call createUniqueId()
String uid = uniqueIdVendor.createUniqueId(faceletContext.getFacesContext(),
mctx.getSharedStringBuilder()
.append(compositeComponentBase.getId())
.append("__f_")
.append("cc_facet").toString());
compositeFacetPanel.setId(uid);
}
}
// Before call applyCompositeComponent we need to add ajax behaviors
// to the current compositeComponentBase. Note that super.applyNextHandler()
// has already been called, but this point is before vdl.retargetAttachedObjects,
// so we can't but this on ComponentTagHandlerDelegate, if we want this to be
// applied correctly.
Iterator<AjaxHandler> it = ((AbstractFaceletContext) faceletContext).getAjaxHandlers();
if (it != null)
{
while(it.hasNext())
{
mctx.addAttachedObjectHandler(
compositeComponentBase, it.next());
}
}
VariableMapper orig = faceletContext.getVariableMapper();
try
{
faceletContext.setVariableMapper(new VariableMapperWrapper(orig));
actx.pushCompositeComponentClient(this);
Resource resourceForCurrentView = faceletContext.getFacesContext().getApplication().
getResourceHandler().createResource(_resource.getResourceName(), _resource.getLibraryName());
if (resourceForCurrentView != null)
{
//Wrap it for serialization.
resourceForCurrentView = new CompositeResouceWrapper(resourceForCurrentView);
}
else
{
//If a resource cannot be resolved it means a default for the current
//composite component does not exists.
throw new TagException(getTag(), "Composite Component " + getTag().getQName()
+ " requires a default instance that can be found by the installed ResourceHandler.");
}
actx.applyCompositeComponent(compositeFacetPanel, resourceForCurrentView);
}
finally
{
actx.popCompositeComponentClient();
faceletContext.setVariableMapper(orig);
}
}