Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazy loading f:selectItems when opening p:selectOneMenu

I would like to load list of <f:selectItems> only when user opens <p:selectOneMenu>.

I tried this way but doesn't work:

<p:selectOneMenu id="bases" value="#{sucesoBB.suceso.base}" converter="EntitiesCachedConverter"  >
    <f:selectItem itemLabel="" itemValue="" />
    <f:selectItems value="#{sucesoBB.bases}" var="base" itemValue="#{base}" itemLabel="#{base.id} - #{base.descripcion}"  />
    <p:ajax event="click" onstart="#{sucesoBB.bases == null or sucesoBB.bases.size() ==1 or sucesoBB.bases.empty()?'cargaBases();':''}" />
</p:selectOneMenu>
<p:remoteCommand name="cargaBases" update="bases" actionListener="#{sucesoBB.cargaBases}" />

How can I achieve this?

like image 419
Mathew Rock Avatar asked Nov 09 '22 05:11

Mathew Rock


1 Answers

A "dynamic" attribute was recently added to the selectOneMenu component.

Just add it like this: <p:selectOneMenu dynamic="true" ... >

https://github.com/primefaces/primefaces/issues/2399

Demo: https://www.primefaces.org/showcase/ui/input/oneMenu.xhtml

You need to have at least Primefaces version 6.0.20, 6.1.2 or 6.2

like image 70
Max Avatar answered Nov 15 '22 10:11

Max