How to update SelectOneMenu without closing dropdown list

118 Views Asked by At

I load selectOneMenu items on ajax event "focus" because list of items is to big and I do not want to prepare it on Bean loading. The best way for me it is to load it on selectOneMenu focus. After list loading Jsf needs to update selectOneMenu component but it closes dropdownlist every time. Is it way to update selectOneMenu items without closing dropDownList?

<p:selectOneMenu id="companyEntity"
                 value="#{docBean.docIncomingEntity.companyEntity}"
                 effect="fade"
                 rendered="#{docBean.companyPersonSwitch == 0}"
                 filter="true"
                 converter="omnifaces.SelectItemsConverter"
                 filterMatchMode="contains">
    <f:selectItems value="#{companyBean.companyEntityList}"
                   itemLabel="#{item.name}"
                   itemValue="#{item}"
                   var="item"/>
    <p:ajax event="focus" listener="#{companyBean.loadAllCompaniesList()}" update="companyEntity"/>
</p:selectOneMenu>
1

There are 1 best solutions below

0
Jasper de Vries On

You don't need to build lazy loading yourself. PrimeFaces has built in lazy loading for the p:selectOneMenu component. You simply have to add the attribute dynamic="true" and it will lazy load the items. You can find a demo in the showcase.

See:

If you really have a lot of items, you are better of using 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: