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}" />
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) {...}
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With