简体   繁体   English

Primefaces selectOneMenu 延迟加载不起作用

[英]Primefaces selectOneMenu lazy loading does not work

I trie do not load selectOneMenu list when xhtml loading, because list is to big.我尝试在加载 xhtml 时不加载 selectOneMenu 列表,因为列表太大。 I set parameter dynamic="true" to have lazy loading, but selectOneMenu always loads the list on xhtml loading.我将参数 dynamic="true" 设置为延迟加载,但 selectOneMenu 始终在 xhtml 加载时加载列表。 But I want to load it only when user starts to use selectOneMenu.但我只想在用户开始使用 selectOneMenu 时加载它。

My xhtml我的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. p:selectOneMenudynamic="true"属性将在菜单首次打开时使用 Ajax 调用从 bean 加载项,而不是页面加载。 The actual data in the bean will be loaded when the bean is constructed and not in that Ajax call. bean 中的实际数据将在构造 bean 时加载,而不是在 Ajax 调用中加载。

If you want your data to be loaded lazily as well you should use the p:autoComplete component.如果您也希望延迟加载数据,则应该使用p:autoComplete组件。 AutoComplete displays suggestions while the input is being type. AutoComplete 在输入时显示建议。 It features various options, customizable content, multiple selection, effects and events.它具有各种选项、可定制的内容、多重选择、效果和事件。

See:看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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