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 are very poorly documented, so in most cases you must go to the source code and check yourself.
p:selectOneMenu
supports change event:which triggers listener with
AjaxBehaviourEvent
as argument in signature:I'd rather use more convenient
itemSelect
event. With this event you can useorg.primefaces.event.SelectEvent
objects in your listener.With such listener:
Be carefull that the page does not contain any empty component which has "required" attribute as "true" before your selectOneMenu component running.
If you use a component such as
then,
and forget to fill the required component, ajax listener of selectoneMenu cannot be executed.
You could check whether the value of your
selectOneMenu
component belongs to the list of subjects.Namely:
Supposedly
subjectList
is a collection type, likeArrayList
. Of course here your code will run in case the user writes an item of yourselectOneMenu
list.