简体   繁体   中英

Primefaces selectOneMenu lazy loading does not work

I trie do not load selectOneMenu list when xhtml loading, because list is to big. I set parameter dynamic="true" to have lazy loading, but selectOneMenu always loads the list on xhtml loading. But I want to load it only when user starts to use selectOneMenu.

My xhtml

<p:selectOneMenu id="companyEntity"
                 value="#{docBean.docIncomingEntity.companyEntity}"
                 effect="fade"
                 style="width: 100%"
                 dynamic="true"
                 filter="true"
                 converter="omnifaces.SelectItemsConverter">
    <f:selectItems value="#{companyBean.loadAllCompaniesList()}"
                   itemLabel="#{item.name}"
                   itemValue="#{item}"
                   var="item"/>
</p:selectOneMenu>

My Bean

...
public List<CompanyEntity> loadAllCompaniesList() {
    return companyDAO.selectAllCompanies();
}

My DAO

public List<CompanyEntity> selectAllCompanies() {
    return em.createQuery("select a from CompanyEntity a order by a.name", CompanyEntity.class)
            .getResultList();
}

The dynamic="true" attribute of the p:selectOneMenu will load the items from the bean using an Ajax call when the menu is first opened instead of page load. The actual data in the bean will be loaded when the bean is constructed and not in that Ajax call.

If you want your data to be loaded lazily as well you should use the p:autoComplete component. AutoComplete displays suggestions while the input is being type. It features various options, customizable content, multiple selection, effects and events.

See:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM