selectOneMenu ajax events

leostiw picture leostiw · May 16, 2013 · Viewed 118.5k times · Source

I am using an editable primefaces selectOneMenu to display some values. If the user selects an item from the List a textarea should be updated. However, if the user types something in the selectOneMenu, the textarea should not be updated.

I thought I could work this with ajax event out. However, I don't know which event I can use here. I only know the valueChange event. Are there any other events, like onSelect or onKeyUp?

Here is my code:

<p:selectOneMenu id="betreff" style="width: 470px !important;"  
            editable="true" value="#{post.aktNachricht.subject}">
            <p:ajax event="valueChange" update="msgtext"
                listener="#{post.subjectSelectionChanged}" />
            <f:selectItems value="#{post.subjectList}" />
</p:selectOneMenu>

<p:inputTextarea style="width:550px;" rows="15" id="msgtext"
        value="#{post.aktNachricht.text}" />

Answer

Danubian Sailor picture Danubian Sailor · Feb 7, 2014

The PrimeFaces ajax events sometimes are very poorly documented, so in most cases you must go to the source code and check yourself.

p:selectOneMenu supports change event:

<p:selectOneMenu ..>
    <p:ajax event="change" update="msgtext"
        listener="#{post.subjectSelectionChanged}" />
    <!--...-->
</p:selectOneMenu>

which triggers listener with AjaxBehaviorEvent as argument in signature:

public void subjectSelectionChanged(final AjaxBehaviorEvent event)  {...}