How to update the label of p:selectCheckboxMenu without the component being closed after ajax call in primefaces?
16,138
Here is how
add widgetVar="someVarName"
to your p:selectCheckboxMenu
and modify your p:"ajax
by adding oncomplete="someVarName.show()"
complete code :
<p:selectCheckboxMenu widgetVar="someVarName" value="#{usersManagmentPage.selectedMovies}"
label="#{usersManagmentPage.moviesLabel}" id="Movies" >
<f:selectItems value="#{usersManagmentPage.movies}" ></f:selectItems>
<p:ajax oncomplete="someVarName.show()" listener="#{usersManagmentPage.populateLabel}" update="Movies" ></p:ajax>
</p:selectCheckboxMenu>
In latest PrimeFaces you should use oncomplete="PF('someVarName').show()"
instead of oncomplete="someVarName.show()"
Author by
Sri Harsha
Updated on June 20, 2022Comments
-
Sri Harsha almost 2 years
There is one problem occurring when I am trying to dynamically generate the label from the backing bean. The problem is that the dropdown that appears vanishes for each selection but the label is updated properly. Is there a workaround for this?
<p:selectCheckboxMenu value="#{formBean.selectedMovies}" label="#{formBean.moviesLabel}" id="Movies" > <f:selectItems value="#{formBean.movies}" ></f:selectItems> <p:ajax update="Movies" listener="#{formBean.populateLabel}"></p:ajax> </p:selectCheckboxMenu>
and
//Backing bean public void populateLabel() { /* Populating the label with the selected options */ moviesLabel = new String(""); if (selectedMovies.size() == 0) { moviesLabel = "Select"; } else { for (int i = 0; i < selectedMovies.size(); i++) { if (moviesLabel.length() == 0) { moviesLabel = selectedMovies.get(i); } else { moviesLabel = moviesLabel + "," + selectedMovies.get(i); } } } }
-
Daniel about 12 yearsare you working with the latest nightly build ? code.google.com/p/primefaces/issues/detail?id=3627 if you aren't, then try... repository.primefaces.org/org/primefaces/primefaces/…
-
Sri Harsha about 12 yearsHi ... thanks for the reply ... I added the build to my project ... i tried giving it an event and trying to do the same but i still have the same problem ... Also i would like to know if the new build has anyother evnet like "onmenuclose" apart from the change event ???
-
Sri Harsha about 12 yearsI would like to tell you that the previous method does work but the problem is that every time a selection is made the menu closes and then i would have open the menu again to make any other selection.
-
Daniel about 12 yearsYou mean that adding an up to date jar solved the original problem?
-
Sri Harsha about 12 years@Daniel: Hi, no i meant that the problem still persists even after adding the upto date jar . I want to know if apart from the "change" event are there any other events like "onmenuclose" associated with the pre-built <p:ajax> event. If there is then my problem will be solved . I went through the documentation and searched on google but there is stunning lack of any information on the events associated with them .
-
-
Nitek almost 9 yearsIn case someone is also wondering: By now you have to use oncomplete="PF('someVarName').show()" to make it work - Took me a while to figure out
-
jpvee about 7 yearsSort of works, but with this solution, when the menu is opened again by show(), it is always re-positionend at the top of the menu item list, which can be a PITA when you have meny entries. Any ideas on how to work around this behavior?
-
jansohn over 6 yearsAlso deselecting an item does not work in my case. It gets immediately reselected.
-
Yasin about 4 yearsthis is work but widget position is different location point on page. I have datatable and its each of cell include selectCheckboxMenu
-
Tadas B. over 2 yearsSelecting All values does not call a listener...