change selected item of selectonemenu primefaces by managedbean of javascript

atbegin-but picture atbegin-but · Apr 1, 2013 · Viewed 14.8k times · Source

I want to change the selected value of this selectOneMenu either by managed bean or javascript:

<p:selectOneMenu id="edit-article-famille" widgetVar="editFamille"
    required="true" requiredMessage="Veuillez choisir une famille"
    value="#{articlesMB.selectedFamille}">
  <f:selectItem itemLabel="selectionner famille" itemValue=""/>
  <f:selectItems value="#{articlesMB.listFamilles}"/>
</p:selectOneMenu>

How can I do it? In the primefaces user guide, they don't talk about that.

Answer

partlov picture partlov · Apr 1, 2013

You can set value of your p:selectOneMenu with widgetVar in JavaScript:

editFamille.selectValue(value);

value is value of selectItem.

Or in more recent versions of PrimeFaces via

PF('editFamille').selectValue(value)