15

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);
            }
        }
    }
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Sri Harsha
  • 319
  • 1
  • 4
  • 12
  • are you working with the latest nightly build ? http://code.google.com/p/primefaces/issues/detail?id=3627 if you aren't, then try... http://repository.primefaces.org/org/primefaces/primefaces/3.3-SNAPSHOT/ – Daniel Apr 01 '12 at 14:07
  • Hi ... 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 Apr 01 '12 at 15:46
  • I 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. – Sri Harsha Apr 01 '12 at 15:49
  • You mean that adding an up to date jar solved the original problem? – Daniel Apr 01 '12 at 17:14
  • @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 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 . – Sri Harsha Apr 02 '12 at 03:29

1 Answers1

24

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()"

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • 1
    In 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 – Nitek Jul 07 '15 at 09:07
  • 4
    Sort 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? – jpvee May 22 '17 at 10:43
  • Also deselecting an item does not work in my case. It gets immediately reselected. – jansohn Oct 24 '17 at 09:20
  • this is work but widget position is different location point on page. I have datatable and its each of cell include selectCheckboxMenu – Yasin Mar 05 '20 at 08:08
  • Selecting All values does not call a listener... – Tadas B. Jan 03 '22 at 18:52