amb
amb

Reputation: 1609

p:selectBooleanCheckbox and the label attached to it

The natural behaviour for a label attached to a checkbox button is to change the state of the button when it (the label) is clicked. This works in JSF and Richfaces.

Is there a way to make it work in Primefaces(3.5) without involving javascript ? Is this a bug ?

<p:outputLabel for="checkbox" value="Select it:" />
<p:selectBooleanCheckbox id="checkbox" label="My label" value="#{bean.value}" />

Upvotes: 8

Views: 11147

Answers (2)

Jasper de Vries
Jasper de Vries

Reputation: 20168

This bug has been fixed since PrimeFaces 4, so you can use p:outputLabel with recent versions of PrimeFaces. Good thing of the p:outputLabel is that it allows you to add body content to it. So you can add images, icons, a link to terms and conditions, etc.

<p:selectBooleanCheckbox value="#{bean.value}"/>
<p:outputLabel for="@previous">
    Label to <strong>click</strong>
</p:outputLabel>

Upvotes: 0

Matt Handy
Matt Handy

Reputation: 30025

It doesn't work out-of-the-box in plain JSF but in PrimeFaces the itemLabel attribute should do it:

<p:selectBooleanCheckbox id="checkbox" itemLabel="My label" ... />

Upvotes: 15

Related Questions