blob: 47abc82ac5a0b744ba8046f3ccb7a4ae633e3b4d [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.html5.component.util;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
public class ComponentUtils {
public static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
{
UIComponent parent = component.getParent();
if (returnRootIfNotFound && parent == null)
{
return component;
}
while (parent != null)
{
if (parent instanceof NamingContainer)
return parent;
if (returnRootIfNotFound)
{
UIComponent nextParent = parent.getParent();
if (nextParent == null)
{
return parent; // Root
}
parent = nextParent;
}
else
{
parent = parent.getParent();
}
}
return null;
}
//copied from org.apache.myfaces.commons.exporter.util.ComponentUtils
public static String getPathToComponent(UIComponent component) {
StringBuffer buf = new StringBuffer();
if (component == null)
{
buf.append("{Component-Path : ");
buf.append("[null]}");
return buf.toString();
}
getPathToComponent(component, buf);
buf.insert(0, "{Component-Path : ");
buf.append("}");
return buf.toString();
}
//copied from org.apache.myfaces.commons.exporter.util.ComponentUtils
private static void getPathToComponent(UIComponent component,
StringBuffer buf) {
if (component == null)
return;
StringBuffer intBuf = new StringBuffer();
intBuf.append("[Class: ");
intBuf.append(component.getClass().getName());
if (component instanceof UIViewRoot)
{
intBuf.append(",ViewId: ");
intBuf.append(((UIViewRoot) component).getViewId());
}
else
{
intBuf.append(",Id: ");
intBuf.append(component.getId());
}
intBuf.append("]");
buf.insert(0, intBuf.toString());
getPathToComponent(component.getParent(), buf);
}
}