SelectOneRadio is used to choose a single item from a collection.
<style>
.grid-radio td {
padding: .5rem;
}
.legend {
display: inline-block;
width: 1.5rem;
height: 1.5rem;
border-radius: .25rem;
vertical-align: sub;
}
</style>
<div class="card">
<h:form>
<h5 class="mt-0">Line Direction</h5>
<p:selectOneRadio id="line" value="#{radioView.line}" layout="lineDirection">
<f:selectItem itemLabel="Option1" itemValue="Option1"/>
<f:selectItem itemLabel="Option2" itemValue="Option2"/>
<f:selectItem itemLabel="Option3" itemValue="Option3"/>
</p:selectOneRadio>
<h5>Page Direction</h5>
<p:selectOneRadio id="page" value="#{radioView.page}" layout="pageDirection">
<f:selectItem itemLabel="Option1" itemValue="Option1"/>
<f:selectItem itemLabel="Option2" itemValue="Option2"/>
<f:selectItem itemLabel="Option3" itemValue="Option3"/>
</p:selectOneRadio>
<h5>Responsive + Unselectable</h5>
<p:selectOneRadio id="city2" value="#{radioView.city2}" layout="responsive" columns="3" unselectable="true">
<f:selectItems value="#{radioView.cities}" var="city" itemLabel="#{city}" itemValue="#{city}"/>
</p:selectOneRadio>
<h5>Custom Layout (Facet)</h5>
<p:selectOneRadio id="customRadio" value="#{radioView.color}">
<f:selectItem itemLabel="Red" itemValue="Red"/>
<f:selectItem itemLabel="Green" itemValue="Green"/>
<f:selectItem itemLabel="Blue" itemValue="Blue"/>
<f:facet name="custom">
<span class="field-radiobutton">
<p:radioButton id="facet1" for="customRadio" itemIndex="0"/>
<p:outputLabel for="facet1">
<span class="legend" style="background:red"/> Red
</p:outputLabel>
</span>
<span class="field-radiobutton">
<p:radioButton id="facet2" for="customRadio" itemIndex="1"/>
<p:outputLabel for="facet2">
<span class="legend" style="background:green"/> Green
</p:outputLabel>
</span>
<span class="field-radiobutton">
<p:radioButton id="facet3" for="customRadio" itemIndex="2"/>
<p:outputLabel for="facet3">
<span class="legend" style="background:blue"/> Blue
</p:outputLabel>
</span>
</f:facet>
</p:selectOneRadio>
<h5>Custom Layout (Referenced)</h5>
<p:selectOneRadio id="customRadio2" value="#{radioView.color2}" layout="custom">
<f:selectItem itemLabel="Red" itemValue="Red"/>
<f:selectItem itemLabel="Green" itemValue="Green"/>
<f:selectItem itemLabel="Blue" itemValue="Blue"/>
</p:selectOneRadio>
<div class="flex flex-column gap-3">
<div class="flex align-items-center gap-2">
<p:radioButton id="ref1" for="customRadio2" itemIndex="0"/>
<span class="legend" style="background:red"/>
<p:outputLabel for="ref1" value="Red"/>
</div>
<div class="flex align-items-center gap-2">
<p:radioButton id="ref2" for="customRadio2" itemIndex="1"/>
<span class="legend" style="background:green"/>
<p:outputLabel for="ref2" value="Green"/>
</div>
<div class="flex align-items-center gap-2">
<p:radioButton id="ref3" for="customRadio2" itemIndex="2"/>
<span class="legend" style="background:blue"/>
<p:outputLabel for="ref3" value="Blue"/>
</div>
</div>
</h:form>
</div>