0
votes

I want to use other primefaces components in p:menuitem. Components display in page but actionlistener doesn't work and inputtext's value doesn't push to bean's value1 attribute. Is there any way to handle this problem?

<p:commandButton id="dynaButton" value="Search" type="button" icon="ui-icon-extlink"/>
<p:slideMenu overlay="true" trigger="dynaButton" my="left top" at="left bottom" style="width:180px">
    <p:submenu label="Search">
        <p:menuitem>
            <p:outputLabel value="Search by Id" />
            <p:inputText value="#{bean.value1}" />
            <p:commandButton value="save" actionListener="#{bean.method1}"  />
        </p:menuitem>
    </p:submenu>
    <p:submenu label="Search By Product">
        <p:menuitem value="Delete"  ajax="false" icon="ui-icon-close"/>
    </p:submenu>
    <p:submenu label="Location" icon="ui-icon-extlink">
        <p:submenu label="Prime Links">
            <p:menuitem value="Prime" url="http://www.prime.com.tr" />
            <p:menuitem value="PrimeFaces" url="http://www.primefaces.org" />
        </p:submenu>
        <p:menuitem value="Mobile" />
    </p:submenu>
</p:slideMenu>
2

2 Answers

0
votes

Try change your code to the following:

        <p:menuitem>
            <p:outputLabel value="Search by Id" />
            <p:inputText id="inputField" value="#{bean.value1}" />
            <p:commandButton process="inputField @this" value="save" actionListener="#{bean.method1}"  />
        </p:menuitem>

Check these answers too:

Why to add process=“@this” explicitly to p:commandButton to get action invoked?

Understanding process and update attributes of PrimeFaces

0
votes

You miss the update attribute.

Note that menuitems can be directly processed, but cannot be directly updated, you need to update the entire menu

<p:slideMenu id="menu" ...>
    <p:submenu label="Search">
        <p:menuitem id="item">
            <p:outputLabel value="Search by Id" />
            <p:inputText value="#{bean.value1}" />
            <p:commandButton value="save" actionListener="#{bean.method1}" process="item" update="menu" />
            <h:outputText value="#{bean.value1}" />
        </p:menuitem>
    </p:submenu>
</p:slideMenu>