* @param clientId The component <code>clientId</code> for which to
* obtain a {@link LayoutComponent}.
*/
public static LayoutComponent getLayoutComponent(FacesContext ctx, String ldKey, String clientId) throws LayoutDefinitionException {
// Find the page first...
LayoutElement layElt = null;
if (ldKey != null) {
// FIXME: This fixme probably belongs in getLD(ctx, key): initPage should only be invoked if the page is accessed for the first time on the request. This potentially calls it multiple times.
layElt = getLayoutDefinition(ctx, ldKey);
if (layElt == null) {
throw new LayoutDefinitionException(
"Unable to find LayoutDefinition ('" + ldKey + "')");
}
} else {
layElt = ViewRootUtil.getLayoutDefinition(
FacesContext.getCurrentInstance().getViewRoot());
}
// Save the current LayoutComposition Stack
// - This is needed b/c we may be in the middle of walking the tree
// - already and we need ot use this Stack... so we must save the
// - Stack and use a fresh one. We must restore it later.
Stack<LayoutElement> oldStack = LayoutComposition.getCompositionStack(ctx);
try {
LayoutComposition.setCompositionStack(
ctx, new Stack<LayoutElement>());
// Create a StringTokenizer over the clientId
StringTokenizer tok = new StringTokenizer(clientId, ":");
// Walk the LD looking for the individual id's specified in the
// clientId.
String id = null;
LayoutElement match = null;
while (tok.hasMoreTokens()) {
// I don't want to create a bunch of objects to check for
// instanceof NamingContainer. I can't check the class file
// b/c there is no way for me to know what class gets created
// before actually creating the UIComponent. This is because