7

I have a SelectCheckBoxMenu (Primefaces component) with plenty of entries. However, the user is allowed to select max. 3 items. SelectCheckBoxMenu fullfils almost all my requirements, the only problem is that it offers the possibility to select all items, which i obviously don't need in this case.

Is there any possility to disable the "select-all" option? I am using an event to check the entries for max. 3. I think I could do the same for "select-all" and not allow him to select them, but I don't want to have the "select-all" option at all.

Below the code:

<p:selectCheckboxMenu value="#{services.titelId}" id="titel" 
            panelStyle="width:160px;" rendered="#{!services.isFirma()}"
            label="#{services.prepareTitel()}" style="width:160px;"
            styleClass="checkbox">
            <f:selectItems value="#{meta.getAkadTitelList()}" />
            <p:ajax event="change" listener="#{services.validateTitel()}"
                update="titel" process="@this" />
            <p:ajax event="toggleSelect" update="titel" process="@this" />
</p:selectCheckboxMenu>

In addition, the link to the primefaces-showcase example: https://www.primefaces.org/showcase/ui/input/checkboxMenu.xhtml

Hendrik
  • 413
  • 7
  • 17
leostiw
  • 1,125
  • 3
  • 12
  • 28

3 Answers3

19

The previous answer did not work for me under PrimeFaces 5.0, so I took a deeper look in the generated HTML and found a solution for PF5 as well.

For PrimeFaces 5.0 you can remove the "select all" checkbox like this:

.without-selectall .ui-selectcheckboxmenu-header .ui-chkbox {
    display: none; 
}

Now use panelStyleClass-attribute instead of styleClass:

<p:selectCheckboxMenu ...
    panelStyleClass="without-selectall"
>
stg
  • 2,757
  • 2
  • 28
  • 55
6

You can add css rule to your css file

#titel .ui-chkbox .ui-widget {
     display:none;
}

You should add prependId="false" to your h:form , or in case you don't want to add prependId="false" you can change the #titel .ui-chkbox .ui-widget selector into something like #myForm\3A titel .ui-chkbox .ui-widget (to handle the : id seperator)


In case you want the entire filter row removed you can set

<p:selectCheckboxMenu filter="false"....
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • Thanks as always, I tried both options, but it didn't work. However, you brought me on the right way, css rule was the answer. I did "remove" the header from the checkboxmenu, which makes sense, it was what i needed. `.ui-selectcheckboxmenu-header { display: none; }` I changed the primefaces css because it makes sense for my project, but if anyone else has the same issues, be aware, do it just for the selectboxmenu you need. Thanks again Daniel. – leostiw Mar 19 '13 at 10:23
  • 1
    You better not change primefacs css , instead add this tule to your own css file and make sure it will be loaded last... so it will override primefaces css... – Daniel Mar 19 '13 at 10:33
  • Oh sorry, I expressed myself badly, I didn't change the primefaces.css, i added this code in my own css. – leostiw Mar 19 '13 at 10:43
  • 6
    You can also just use a classname. E.g. `` and then use `.ui-selectcheckboxmenu.without-selectall` instead of `#titel`. That's more reusable. – BalusC Mar 19 '13 at 12:09
  • Yes, that's the best way to do it, this is what i was trying to say on my first reply: for anyone else, better use your own css declaration. – leostiw Mar 19 '13 at 13:06
  • @BalusC your solution is not working in PF 6.2 as that class is not copied to panel... – Betlista Mar 26 '19 at 20:59
0

You can add <p:selectCheckboxMenu showHeader="false"......

Ashwini
  • 11
  • 1