title: Override Primefaces Renderer
body: <p>I'm developing a dynamic menu using Primefaces and JSF 2.2.</p>
  
  <p>The problem is that it's not inserting the menu id. Looking primefaces' code it hits a code that will always be false:</p>
  
  <p>BaseMenuRenderer:</p>
  
  <pre><code>protected boolean shouldRenderId(MenuElement element) {
      if(element instanceof UIComponent)
          return shouldWriteId((UIComponent) element);
      else
          return false;
  }
  </code></pre>
  
  <p>TieredMenuRenderer:</p>
  
  <pre><code> writer.startElement("li", null);
                      if(shouldRenderId(submenu)) {
                          writer.writeAttribute("id", submenu.getClientId(), null);
                      }
  </code></pre>
  
  <p>So, I decided to override primefaces' TieredMenuRenderer, but my override constructor classe is called but the override method is never called.</p>
  
  <p>Here's how I set my facesconfig.xml</p>
  
  <pre><code>&lt;render-kit&gt;
          &lt;renderer&gt;
              &lt;component-family&gt;org.primefaces.component&lt;/component-family&gt;
              &lt;renderer-type&gt;org.primefaces.component.TieredMenuRenderer&lt;/renderer-type&gt;
              &lt;renderer-class&gt;ui.jsf.TieredMenuRenderer&lt;/renderer-class&gt;
          &lt;/renderer&gt;
      &lt;/render-kit&gt;
  </code></pre>
  
  <p>My override class:</p>
  
  <pre><code>    public class TieredMenuRenderer extends org.primefaces.component.tieredmenu.TieredMenuRenderer {
    @Override
      protected void encodeElements(FacesContext context, AbstractMenu menu, List&lt;MenuElement&gt; elements) throws IOException {
          System.out.println("----------- TEST --------------");
          super.encodeElements(context, menu, elements);
      }
  </code></pre>
  
  <p>Sysout is never print.</p>
  
  <p>Does anyone know what i'm doing wrong? </p>
  
  <p>Thanks!</p>
  
  <p>Edit:</p>
  
  <p>Add ID to DefaultMenuItem:</p>
  
  <pre><code>  DefaultMenuItem item = new DefaultMenuItem();
    item.setId(menuItem.getMenuId());// just return a string value.
  </code></pre>
  
  <p>Adding menu xhtml, the "menucontroller.model" is a primefaces MenuModel which I use a DefaultMenuModel :</p>
  
  <h2>    </h2>
  
  <p>Iterating over renderer kit, When I execute the following command, returns the correct renderer-type <code>org.primefaces.component.TieredMenuRenderer</code></p>
  
  <pre><code>Iterator&lt;String&gt; renderKit = kit.getRendererTypes("org.primefaces.component");
  </code></pre>
  
  <p>When I execute the following code returns my qualified classname <code>ui.jsf.TieredMenuRenderer@64baec0e</code>:</p>
  
  <pre><code>Renderer renderer = kit.getRenderer("org.primefaces.component", "org.primefaces.component.TieredMenuRenderer");
  </code></pre>