Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectOneMenu ajax events

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}" /> 
like image 880
leostiw Avatar asked May 16 '13 12:05

leostiw


2 Answers

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)  {...} 
like image 181
Danubian Sailor Avatar answered Sep 16 '22 11:09

Danubian Sailor


I'd rather use more convenient itemSelect event. With this event you can use org.primefaces.event.SelectEvent objects in your listener.

<p:selectOneMenu ...>     <p:ajax event="itemSelect"          update="messages"         listener="#{beanMB.onItemSelectedListener}"/> </p:selectOneMenu> 

With such listener:

public void onItemSelectedListener(SelectEvent event){     MyItem selectedItem = (MyItem) event.getObject();     //do something with selected value } 
like image 37
Michał Stochmal Avatar answered Sep 16 '22 11:09

Michał Stochmal