dump JSF Components Tree - Java JSF

Java examples for JSF:UIComponent

Description

dump JSF Components Tree

Demo Code

/*//  w w  w .  ja v a 2  s .  c  om
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;

public class Main{
    public static void main(String[] argv) throws Exception{
        dumpComponentsTree();
    }
    public static void dumpComponentsTree(List<UIComponent> componetns,
            int level) {
        if ((componetns == null) || (componetns.size() == 0)) {
            return;
        }

        StringBuffer levelString = new StringBuffer();
        for (int i = 0; i < level; i++) {
            levelString.append(" ");
        }

        for (UIComponent comp : componetns) {
            System.out.println(levelString + comp.getId());
            if (comp.getChildCount() > 0) {
                dumpComponentsTree(comp.getChildren(), level++);
            }
        }
    }
    public static void dumpComponentsTree() {
        dumpComponentsTree(FacesContext.getCurrentInstance().getViewRoot()
                .getChildren(), 0);
    }
}

Related Tutorials