Note that there are some explanatory texts on larger screens.

plurals
  1. POPrimefaces 2 MenuItem Action, ActionExpression or ActionListener
    primarykey
    data
    text
    <p>I have an existing working Primefaces 2 MenuBar with the MenuItems defined as follows:</p> <pre><code>&lt;p:menubar style="width:625px" autoSubmenuDisplay="true"&gt; &lt;p:submenu label="#{messages.label_home}"&gt; &lt;p:menuitem value="#{messages.label_logout}" url="#" icon="ui-icon ui-icon-close"/&gt; &lt;/p:submenu&gt; &lt;p:submenu label="#{messages.label_cockpit}"&gt; &lt;p:menuitem value="#{messages.label_create}" action="#{cockpitMenuBean.displayCreateDialog}" icon="ui-icon ui-icon-document" ajax="false"/&gt; &lt;p:menuitem value="#{messages.label_list}" action="#{cockpitMenuBean.displayList}" icon="ui-icon ui-icon-folder-open" ajax="false"/&gt; &lt;/p:submenu&gt; </code></pre> <p>I want to move the menu model from the xhtml to a backing bean as follows:</p> <pre><code>&lt;p:menubar style="width:625px" autoSubmenuDisplay="true" model="#{cockpitMenuBean.menuModel}"/&gt; </code></pre> <p>The problem and my question is centered on the <code>action</code> attribute above.</p> <p>The CockpitMenuBean.displayCreateDialog() returns a string</p> <pre><code>public String displayCreateDialog() { cockpitMenu = new CockpitMenu(); createDialogVisible = true; return "cockpitMenu"; } </code></pre> <p><code>menuItem.setAction(arg);</code> which seemed like it should be the same as the <code>action</code> attribute in the XHTML is looking for arg to be a <code>MethodBinding</code> which is deprecated.</p> <p><code>menuItem.setActionExpression(arg)</code> is next most likely since the string in the XHTML is an EL expression <code>#{cockpitMenuBean.displayCreateDialog}</code>, but that just returns a String. </p> <p><code>menuItem.setActionListener(arg)</code> is deprecated.</p> <p>I am not connecting the dots in moving from the XHTML to the backing bean in building the menuitems that correspond.</p> <p>I tried:</p> <pre><code>MenuItem item1 = new MenuItem(); item1.setValue("Should be first"); item1.setUrl("#"); MethodExpression aEx = expFact.createMethodExpression(elCtx, "#{cockpitMenuBean.displayCreateDialog}", String.class, new Class[0]); item1.setActionExpression(aEx); menuModel.addMenuItem(item1); </code></pre> <p>And the menu item displays but nothing happens when I select it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload