title: findComponent by id in PrimeFaces 3.4 JSF 2.0
body: <p>I want a method which finds a <code>UIComponent</code> by id in PrimeFaces 3.4.
  I already found a method to do this but it has a method visitTree(available in PrimeFaces 5.2) which is not available for PrimeFaces 3.4.</p>
  
  <p>Please can someone help me find panel object in below XHTML.</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;&lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:form id="form"&gt;
          &lt;p:panel id="pnl"&gt;&lt;h:outputText value="Yahoooo...."&gt;&lt;/h:outputText&gt;&lt;/p:panel&gt;
          &lt;p:commandButton ajax="false" value="Toggle" actionListener="#{myBean.mytoggle}"/&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Primefaces 5.2 working method</p>
  
  <pre><code>public UIComponent findComponent(final String id) {
  
      FacesContext context = FacesContext.getCurrentInstance(); 
      UIViewRoot root = context.getViewRoot();
      final UIComponent[] found = new UIComponent[1];
  
      root.visitTree(new FullVisitContext(context), new VisitCallback() {     
          @Override
          public VisitResult visit(VisitContext context, UIComponent component) {
              if(component.getId().equals(id)){
                  found[0] = component;
                  return VisitResult.COMPLETE;
              }
              return VisitResult.ACCEPT;              
          }
      });
  
      return found[0];
  
  }
  </code></pre>