UIComponent currentCompositeComponent = UIComponent.getCurrentCompositeComponent(facesContext);
//1.1 Use getCurrentCompositeComponent first!
if (currentCompositeComponent != null)
{
Location componentLocation = (Location) currentCompositeComponent.getAttributes().get(LOCATION_KEY);
if (componentLocation != null
&& componentLocation.getPath().equals(location.getPath()) &&
(ccLevel == getCCLevel(currentCompositeComponent)) )
{
return currentCompositeComponent;
}
}
UIComponent currentComponent = UIComponent.getCurrentComponent(facesContext);
if (currentComponent == null)
{
// Cannot found any component, because we don't have any reference!
return null;
}
//2. Look on the stack using a recursive algorithm.
UIComponent matchingCompositeComponent
= lookForCompositeComponentOnStack(facesContext, location, ccLevel, currentComponent);
if (matchingCompositeComponent != null)
{
return matchingCompositeComponent;
}
//2. Try to find it using UIComponent.getCurrentCompositeComponent().
// This one will look the direct parent hierarchy of the component,
// to see if the composite component can be found.
if (currentCompositeComponent != null)
{
currentComponent = currentCompositeComponent;
}
else
{
//Try to find the composite component looking directly the parent
//ancestor of the current component
//currentComponent = UIComponent.getCurrentComponent(facesContext);
boolean found = false;
while (currentComponent != null && !found)
{
String findComponentExpr = (String) currentComponent.getAttributes().get(CC_FIND_COMPONENT_EXPRESSION);
if (findComponentExpr != null)
{
UIComponent foundComponent = facesContext.getViewRoot().findComponent(findComponentExpr);
if (foundComponent != null)
{
Location foundComponentLocation = (Location) currentComponent.getAttributes().get(LOCATION_KEY);
if (foundComponentLocation != null
&& foundComponentLocation.getPath().equals(location.getPath()) &&
ccLevel == getCCLevel(foundComponent))
{
return foundComponent;
}
else
{
while (foundComponent != null)
{
Location componentLocation
= (Location) foundComponent.getAttributes().get(LOCATION_KEY);
if (componentLocation != null
&& componentLocation.getPath().equals(location.getPath()) &&
ccLevel == getCCLevel(foundComponent))
{
return foundComponent;
}
// get the composite component's parent
foundComponent = UIComponent.getCompositeComponentParent(foundComponent);
}
}
}
}
if (UIComponent.isCompositeComponent(currentComponent))
{
found = true;
}
else
{
currentComponent = currentComponent.getParent();
}
}
}
//if currentComponent != null means we have a composite component that we can check
//Use UIComponent.getCompositeComponentParent() to traverse here.
while (currentComponent != null)
{
Location componentLocation = (Location) currentComponent.getAttributes().get(LOCATION_KEY);
if (componentLocation != null
&& componentLocation.getPath().equals(location.getPath()) &&
ccLevel == getCCLevel(currentComponent))
{
return currentComponent;
}
// get the composite component's parent