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

Share:
16,138
Sri Harsha
Author by

Sri Harsha

Updated on June 20, 2022

Comments

  • Sri Harsha
    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
      Daniel about 12 years
      are 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
      Sri Harsha about 12 years
      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
      Sri Harsha about 12 years
      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.
    • Daniel
      Daniel about 12 years
      You mean that adding an up to date jar solved the original problem?
    • Sri Harsha
      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
    Nitek almost 9 years
    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
  • jpvee
    jpvee about 7 years
    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?
  • jansohn
    jansohn over 6 years
    Also deselecting an item does not work in my case. It gets immediately reselected.
  • Yasin
    Yasin about 4 years
    this is work but widget position is different location point on page. I have datatable and its each of cell include selectCheckboxMenu
  • Tadas B.
    Tadas B. over 2 years
    Selecting All values does not call a listener...