Sunday, July 15, 2012


A JSF PhaseListener to Print the Component Tree (Example)
Have you ever wondered what the exact makeup of the server side JSF UI component tree in your page?
I was wondering the exact same thing, so I wrote a simple PhaseListener, that dumps the component tree to standard out.
The algorithm is a simple recursive printout of the entire component tree..
Here's the code:
package componentstuff;

import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class PrintComponentTree implements PhaseListener {
  public PrintComponentTree() {
  }

  public int indent = 0;
  public static final int INDENTSIZE = 2;

  public void beforePhase(PhaseEvent PhaseEvent) {
  }

  public void afterPhase(PhaseEvent PhaseEvent) {
    System.out.println("");
    System.out.println("(Rendering Component Tree)");
    printComponentTree(FacesContext.getCurrentInstance().getViewRoot());
  }

  public PhaseId getPhaseId() {
    return PhaseId.RENDER_RESPONSE;    
  }
  
  public void printComponentTree(UIComponent comp){
    printComponentInfo(comp);
    
    List complist = (ArrayList)comp.getChildren();
    if (complist.size()>0)
      indent++;
    for   (int i = 0; i < complist.size(); i++) {
      UIComponent uicom = (UIComponent) complist.get(i);
      printComponentTree(uicom);
      if (i+1 == complist.size())
        indent--;
    }
    
  }

  public void printComponentInfo(UIComponent comp){
  
   if (comp.getId() == null){
     System.out.println("UIViewRoot" + " " + "(" + comp.getClass().getName() + ")");
   } else {
       printIndent();
       System.out.println("|");
       printIndent();
       System.out.println(comp.getId() + " " + "(" + comp.getClass().getName() + ")");
     }  
  }
 
  public void printIndent(){
    for (int i=0; i
Also, don't forget to register it in your faces-config..
  
    componentstuff.PrintComponentTree
  
Here's what the output looks like for a simple Faces page:
06/03/03 17:26:39 (Rendering Component Tree)
06/03/03 17:26:39 UIViewRoot (javax.faces.component.UIViewRoot)
06/03/03 17:26:39   |
06/03/03 17:26:39   form1 (javax.faces.component.html.HtmlForm)
06/03/03 17:26:39     |
06/03/03 17:26:39     panelGrid1 (javax.faces.component.html.HtmlPanelGrid)
06/03/03 17:26:39       |
06/03/03 17:26:39       outputLabel1 (javax.faces.component.html.HtmlOutputLabel)
06/03/03 17:26:39       |
06/03/03 17:26:39       inputText1 (javax.faces.component.html.HtmlInputText)
06/03/03 17:26:39       |
06/03/03 17:26:39       outputLabel2 (javax.faces.component.html.HtmlOutputLabel)
06/03/03 17:26:39       |
06/03/03 17:26:39       inputSecret1 (javax.faces.component.html.HtmlInputSecret)
06/03/03 17:26:39       |
06/03/03 17:26:39       commandButton1 (javax.faces.component.html.HtmlCommandButton)

Feel free to tweak the code however you like!

13 comments:

  1. http://louboutinmart.co.uk Most likely crow or kestrel. [url=http://dkgoose.com]canada goose[/url] Aoacfulrb http://www.louboutinoutletuks.co.uk
    axwplk 242913 [url=http://www.chilliwackbombersoutlet.com]goose image[/url] 150379 [url=http://www.officialcanadagooseparkas.ca]canada goose jackets montreal[/url]

    ReplyDelete
  2. [url=http://louboutinmart.co.uk]christian louboutin uk[/url] as an acronym. [url=http://dkgoose.com]Canada Goose tilbud[/url] Exvlxrakx [url=http://www.louboutinoutletuks.co.uk]louboutin outlet[/url]
    vxdgby 288478 [url=http://www.chilliwackbombersoutlet.com]canada goose freestyle[/url] 258688 [url=http://www.beatsbydreaonsales.com]dr dre[/url]

    ReplyDelete
  3. Major depression is actually a difficult point to
    emerge from, plus it does not matter when the depressive disorders
    is hereditary or perhaps a solution to a heartbreaking function. Nonetheless, there are many
    different treatment options, which includes prescription drugs, psychotherapy and also
    basic behavioral changes. The next article
    provides you with information to aid clear despression symptoms out of your daily life.


    Permit you to ultimately crash often. One of the biggest stuff
    individuals with despression symptoms have a problem with
    is perfectionism. You don't must do everything correct at all times.

    Often you'll get issues wrong, and that's alright.
    Concentrate on what performed go correct as an alternative of what
    gone wrong, and move ahead.

    Among the best ways to take care of depressive disorders
    is as simple as acquiring a new pastime. A stable deficiency
    of curiosity about activities can really become a
    major consider the onset of major depression. Try commencing a new artistic interest or subscribe to a category to reduce feeling of boredom through
    your daily life. Regardless of what suits you, performing something in any
    way will decrease your probability of creating despression symptoms.



    If you're dealing with your personalized concerns, it will help you together with your depressive disorders.
    Using some tiny techniques can stop you from obtaining overwhelmed.
    Just do a couple of tasks at one time. Divide bigger targets into modest goals to
    assist overcome depressive disorders, and this can also
    help resolve some things that are resulting in depression.

    The difference involving specialized medical
    major depression and typical unhappiness is much like the
    main difference from a supply and a stream. If you are you may have been unfortunate for absolutely no reason or remained unfortunate for a long time there exists a possibility you may have scientific major depression. Make sure you
    have this examined by way of a specialist.

    Will not be ashamed when your despression symptoms has pressured you to need to acquire prescription medication. At times, despression symptoms signs or symptoms are so poor the finest points to enable them to are
    medicines. Speak with a psychiatrist to learn if medication is
    a good choice to suit your needs and which medicine is greatest.


    Even though the research on aromatherapy is inconclusive, no specialist will deny the power of scent.

    Possessing a few enjoyable-smelling candle lights getting rid of
    through the residence will help you to feel good effortlessly.

    One of the best fragrances for evoking nice feelings is vanilla, though any fragrance that you like will continue to work.


    As with anything at all, the management of major depression has several scientific studies, approaches, and theories right behind the way
    to treat it. It is additionally fully reliant on the person. Ideally, you possess received help from these guidelines into how to
    start with dealing with your depressive disorders to enable you
    to begin sensing better earlier.

    Feel free to surf to my weblog - hypnose émétophobie

    ReplyDelete
  4. Or patio furniture covers child wooden desk may also be cost prohibitive.
    Make sure that there is a picture. Besides this features,
    beds should be a beaming, vibrant, and inviting kids' room!
    Also watch out for corner posts. If think your baby is too a
    bit older to get a desk. There are different ways of decorating
    and creating your particular one.

    my webpage - children bedspreads ()

    ReplyDelete
  5. basket hommes nike air max tn Cette entreprise air jordan team basketball jerseys est assez célèbre pour la fabrication sportive Nike Shox R3-R4 pour différents sports comme le tennis et air jordan 5 grape gs le basket-ball. C'est certainement l'un des produits et des solutions les asics chaussures trail plus courants offerts à la télévision, et d'innombrables ont déjà été offerts air jordan 11 low concord retail price dans le monde entier. Si nous nous réveillons tous les matins Air Jordan 4 Femme à 6h du matin pour boire un café et basket nike femme presto fly manger des beignets si vous regardez la télé, nous pouvons vous garantir que baskets nike air presto vous vous réveillerez à 6h du matin pour manger sainement et faire du sport.

    ReplyDelete
  6. شركات نقل عفش خارج الرياض
    تتنافس شركات نقل عفش خارج الرياض فيما بينها لتفوز برضا العملاء، وتساعدهم على نقل العفش والأثاث داخل وخارج الرياض أو حتي خارج المملكة، لذلك يمكن للعميل أن يلاحظ إختلاف الأسعار والعروض بين الشركات المختلفة، كما يظهر هذا واضحا على أسلوب تنفيذ الخدمة، فبعض شركات نقل عفش خارج الرياض تقوم بتقليل أسعارها على حساب استخدام أدوات وخامات تحافظ على قطع الأثاث المختلفة أثناء عملية النقل، في حين أن استخدام تلك القطع حتي وإن كان تكلفة إضافية يتحملها العميل وتزيد من التكلفة الإجمالية، إلا أنها تعتبر واجبه للحفاظ على قطع الأثاث من الخدش أو التلف أثناء عملية النقل مما يخفض من إمكانية التلف

    ReplyDelete