Primefaces tooltip for p:selectManyCheckbox or other p:selectMany*/One*

Viewed 9897

I would like to add a tooltip for each element in a p:selectManyCheckBox. However I can't come up with a solution.

I've got a class Role that has 3 properties, "id" (Long), "name" (String) and "description" (String). The name is displayed and I would like to have the description as a tooltip.

This is a working piece of code:

<p:selectManyCheckbox layout="pageDirection" value="#{roleBean.selectedRoles}" converter="roleConverter">
    <f:selectItems value="#{roleBean.roles}" var="role" itemLabel="#{role.name}" itemValue="#{role}"/>
</p:selectManyCheckbox>

The roleConverter is a FacesConverter that converts the Role to an id and visa versa.

I came up with this:

<p:selectManyCheckbox layout="pageDirection" value="#{roleBean.selectedRoles}" converter="roleConverter">
    <c:forEach var="role" items="#{roleBean.roles}">
        <f:selectItem id="role#{role.id}" itemLabel="#{role.name}" itemValue="#{role}" />
        <p:tooltip for="role#{role.id}" value="#{role.description}"/>
    </c:forEach>
</p:selectManyCheckbox>

But unfortunately it doesn't work.

3 Answers

Tooltip support for selectManyCheckbox was added since Primefaces v6.2 version. Other components support this too.

XHTML code is the same BalusC reported

<p:selectManyCheckbox layout="pageDirection" value="#{roleBean.selectedRoles}" converter="roleConverter">
    <f:selectItems value="#{roleBean.roles}" var="role" 
        itemValue="#{role}" itemLabel="#{role.name}" itemDescription="#{role.description}" />
</p:selectManyCheckbox>

but is not anymore required override the PrimeFaces SelectManyCheckboxRenderer

Related