PF 已经有这个组件的网格布局。
<h3>Grid Layout</h3>
<p:selectManyCheckbox id="grid" value="#{checkboxView.selectedCities}" layout="grid" columns="3">
<f:selectItems value="#{checkboxView.cities}" var="city" itemLabel="#{city}" itemValue="#{city}" />
</p:selectManyCheckbox>
但是最新的 PF 5.2.3 和 5.3-SNAPSHOT 有自定义布局选项
<h3>Custom Layout (since v5.2.3)</h3>
<p:outputPanel id="customPanel" style="margin-bottom:20px">
<p:selectManyCheckbox id="custom" value="#{checkboxView.selectedConsoles2}" layout="custom">
<f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
<f:selectItem itemLabel="PS4" itemValue="PS4" />
<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectManyCheckbox>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<p:checkbox id="opt1" for="custom" itemIndex="0" />
</div>
<div class="ui-grid-col-4">
<p:checkbox id="opt2" for="custom" itemIndex="1" />
</div>
<div class="ui-grid-col-4">
<p:checkbox id="opt3" for="custom" itemIndex="2" />
</div>
</div>
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<h:outputLabel for="opt1" value="Xbox One" />
</div>
<div class="ui-grid-col-4">
<h:outputLabel for="opt2" value="PS4" />
</div>
<div class="ui-grid-col-4">
<h:outputLabel for="opt3" value="Wii U" />
</div>
</div>
</div>
</p:outputPanel>
不确定最新功能如何以及是否可以与一个<f:selectItems/>
或仅与多个<f:selectItem/>
. 我怀疑后者
另见:
- 见http://www.primefaces.org/showcase/ui/input/manyCheckbox.xhtml
(取自 PF 展示柜的示例!)