title: Primefaces - How to dynamically add a ContextMenu to a MenuItem
body: <p>I want to programmatically create p:menu with MenuItems (it works) and each MenuItem should has p:contextMenu (it doesn't work).</p>
  
  <p>ManagedBean:</p>
  
  <pre><code>@ManagedBean(name="leftMenuView")
  @SessionScoped
  public class LeftMenuView {
  
      private MenuModel model;
  
      @PostConstruct
      public void init() {
          model = new DefaultMenuModel();   
          DefaultMenuItem item = new DefaultMenuItem("Redirect");
          item.setId("redirectMenuItem");
          model.addElement(item);
  
          ContextMenu ctxMenu = new ContextMenu();
          ctxMenu.setFor("redirectMenuItem");
          MenuModel ctxModel = new DefaultMenuModel();
          MenuItem ctxItem = new DefaultMenuItem("Remove from favorities");
          ctxModel.addElement(ctxItem);
  
          ctxMenu.setModel(ctxModel);
  
      }
  
  (...)
  }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;h:form id="leftForm"&gt;
      &lt;p:menu id="leftMenu" model="#{leftMenuView.model}" /&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Menu appears, but ContextMenu were not shown when I do right-click on MenuItem with "Redirect" label.</p>
  
  <p>What I am doing wrong?</p>
  
  <p><strong>UPDATE - When I add:</strong></p>
  
  <pre><code>uiComponent = (UIComponent) rootView
              .findComponent("leftForm");
  uiComponent.getChildren().add(ctxMenu);
  </code></pre>
  
  <p>It displays context menu on whole Menu bar. This ist unimportant that I have clicked MenuItem or just Menu component.</p>
  
  <p>When I change it to:</p>
  
  <pre><code>uiComponent = (UIComponent) rootView
              .findComponent(":leftForm:leftMenu:redirectMenuItem");
  uiComponent.getChildren().add(ctxMenu);
  </code></pre>
  
  <p>I get "java.lang.IllegalArgumentException: leftMenu"</p>
  
  <p><strong>In other words - I want to get this behaviour:</strong></p>
  
  <pre><code>&lt;h:form&gt;
      &lt;p:menu id="menu_id"&gt;
          &lt;p:menuitem id="gmail_id" value="Gmail"/&gt;
          &lt;p:menuitem id="hotmail_id" value="Hotmail" /&gt;
      &lt;/p:menu&gt;
      &lt;p:contextMenu for="gmail_id"&gt;
          &lt;p:menuitem value="Save" /&gt;
          &lt;p:menuitem value="Delete"/&gt;
      &lt;/p:contextMenu&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>but programmatically (from source code).</p>