In my project i'm using JSF 2.0 and Primefaces 3.5.
In one page i have a p:dataTable and the tables one column has selectBooleanCheckbox. I tried both of p:selectBooleanCheckbox and h:selectBooleanCheckbox. My code like as follow:
<h:panelGrid columns="3">
<p:selectBooleanCheckbox id="id" value="false" />
<p:selectBooleanCheckbox id="id" value="true" />
<p:dataTable id="tbl" value="#{bean.items}" var="item" paginator="false">
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
<p:column style="white-space:normal; text-align: center;">
<p:selectBooleanCheckbox id="id" value="#{item.checked}" />
<p:selectBooleanCheckbox id="id" value="true" />
<p:selectBooleanCheckbox id="id" value="false" />
<h:selectBooleanCheckbox id="id" value="true" />
<h:selectBooleanCheckbox id="id" value="false" />
</p:column>
</p:dataTable>
</h:panelGrid>
And the result:

I want to show correct case of selectBooleanCheckbox. Any suggestions?
You should use #{true} or #{false} instead of true or false
like this:
<p:selectBooleanCheckbox id="id" value="#{true}" />
You do not seem to be linking the checkbox to any value in your backing bean. Try storing the value in your backing bean and having it be reflected in your checkbox. For instance,
Backing Bean:
private Boolean value1 = true;
private Boolean value2 = false;
//appropriate getters and setters for the above values
JSF Page Fragment:
<p:selectBooleanCheckbox value="#{backingbean.value1}" itemLabel="Value 1"/>
<p:selectBooleanCheckbox value="#{backingbean.value2}" itemLabel="Value 2"/>
This should result in the first checkbox being checked (because value1 = true) and the second should not be as value2 = false. In this manner, whenever you click a checkbox it's value will also be reflected in value1 and value2 respectively.
Hope that helps...
Also, @navand is correct in saying to use #{true} and #{false} if you want to manually set the checkbox to be checked or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With