I have a JSF template (xhtml) and I have some checkboxes. But then the page loads I need check boxes to be checked.
Here is my code:
<h:selectManyCheckbox
layout="pageDirection"
required="true"
value="#{myBean.values}">
<f:selectItem itemValue="v1" itemLabel="l1"/>
<f:selectItem itemValue="v2" itemLabel="l2"/>
<f:selectItem itemValue="v3" itemLabel="l3"/>
<f:selectItem itemValue="v4" itemLabel="l4"/>
<f:selectItem itemValue="v5" itemLabel="l5"/>
</h:selectManyCheckbox>
How can I make the checkboxes to be selected when page is loaded? I can find any tags in JSF that specifies checkbox to be checked.
In your code,
#{myBean.values}holds the selected values (the checked checkboxes in this case). So you must make sure thatmyBean.valuescontains theitemValueitems of theselectItems you want to see checked. For example:In the above, populate
myBean.valueswith"v1"and"v2"to show them as checked.