在数据表之外使用p:selectOneRadio,并将layout 属性设置为“自定义”。用f:selectItems 填充这个收音机,这与通过“value”参数提供给dataTable 的数据相同。
<p:selectOneRadio id="customRadio"
value="#{beanMB.selectedItem}"
layout="custom">
<f:selectItems value="#{beanMB.tableItems}"
var="item"
itemValue="#{item.radioValue}"
itemLabel="#{item.radioLabel}"/>
</p:selectOneRadio>
在dataTable列中使用p:radioButton和itemIndex匹配当前rowIndex。
<p:dataTable var="item"
rowIndexVar="rowIndex"
value="#{beanMB.tableItems}">
<p:column headerText="Choice">
<p:radioButton for="@form:customRadio"
itemIndex="#{rowIndex}"
rendered="#{item.radioRendered}"/>
</p:column>
</p:dataTable>