1

I have a selectOneRadio element with layout="custom" inside a dataTable. Below is the xhtml code-

<p:dataTable var="varlist" value="#{testbean.testlist}">
    <p:column headerText="Choose Option" width="120">
        <p:selectOneRadio id="customRadio" value="#{varlist.varlistValue}"
            layout="custom" required="true">
            <f:selectItem itemValue="10" />
            <f:selectItem itemValue="20" />
        </p:selectOneRadio>

        <h:panelGrid columns="1">
            <h:panelGroup>
                <p:radioButton id="opt1" for="customRadio" itemIndex="0" />
                <h:outputLabel for="opt1" value="OPTION 1" styleClass="radiolabelOption"/>
            </h:panelGroup>

            <h:panelGroup>
                <p:radioButton id="opt2" for="customRadio" itemIndex="1" />
                <h:outputLabel for="opt2" value="OPTION 2" styleClass="radiolabelOption"/>
            </h:panelGroup>
        </h:panelGrid>
    </p:column>
</p:dataTable>

<style type="text/css">
    .radiolabelOption {
      margin-left: 10px;
    }
</style>

So this is how it appears in browser-

image1-

As we can see, the outputLabel appears to the bottom with respect to radioButton. But i want that to look centre, w.r.t radioButton as shown below -

enter image description here

I tried below lines of code like

style="display:block; text-align:center" OR
style="margin: 0 auto;"

But none of them produces the desired result.

So How to do it?

1
  • I even tried to raise the height of outputLabel using "margin-bottom:..px" in the style. But it didn't work. Commented Feb 10, 2022 at 8:41

1 Answer 1

1

Give <h:panelGroup> these styles

.panelGroup{
  display: flex;
  align-items: center;
}
5
  • Also, I recommend learning more about flex, it's really useful! Commented Feb 10, 2022 at 8:44
  • That's weird... this shouldn't do anything with margin. Didn't you type something wrong? Commented Feb 10, 2022 at 8:57
  • Looks like that 'display: flex' breaks it. Can you send me styles of 'panelGroup' from browser? Commented Feb 10, 2022 at 9:15
  • Let us continue this discussion in chat. Commented Feb 10, 2022 at 9:18
  • 1
    I did a fresh build for my project & it worked as expected. My bad for not trying that earlier. Thank you :) Commented Feb 10, 2022 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.