How to load the list of items from p:selectOneMenu when clicking to open the dropdown?

Asked

Viewed 1,169 times

1

I would like my p:selectOneMenu to reload the items and show the options every time I click to open the dropdown, has anyone ever tried this? If so, how do I?

  • Why do you need to update the list at the time of the click? Wouldn’t it be better to update the list from an event? (Ex: recording/deleting)

  • Elements that are being manipulated by several different users at the same time will actually be entered in this list, and these various users can add or remove items from this list, so you should update the list every time you open selectOneMenu.

3 answers

1

You can change the get from the list in the bean:

public List<Bla> getListaBla() {
    updateBlaList();
    return this.blaList;
}

0

What if you include a Poll? From time to time you update your select...

<p:poll interval="3" listener="#{counterView.increment}" update="txt_count" />
  • It wouldn’t be a good solution. The query to all items in the list should be done when the user asks, if we had control of the size of the list and this size was very small we could even think about the case even knowing that it would not be the optimal solution...

0

You can fire an ajax request that updates the list..

<p:selectOneMenu value="#{bean.object.property}" id="myId" required="true">
    <f:selectItems value="#{bean.list}" />
    <f:ajax event="click" listener="#{bean.updateList}" />
</p:selectOneMenu>

It is not the ideal way to do.. the best way would be to reload the page already bring all items.

  • I had tried in a similar way. I tried here again and it didn’t work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.