Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectCheckboxMenu - Disable "all-selection"

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

like image 771
leostiw Avatar asked Mar 19 '13 09:03

leostiw


1 Answers

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"
>
like image 113
stg Avatar answered Jan 17 '23 15:01

stg