How to create group h: selectOneRadio in JSF?

I'm trying to create grooup h: selectOneRadio but ui: repeat gives it different ids for each row. This is my code: -

                                <ui:repeat id="themes" value="#{RegisterBean.objBlogTemplateList}" var="item">

                                    <p:graphicImage  alt="#{item.templatePicName}" style="border: solid 5px white;width: 200px;height: 200px;"  value="#{app:getCommonImagePath(item.templatePicName)}"/>

                                    <h:selectOneRadio rendered="false"  value="#{RegisterBean.blogTemplateId}" layout="lineDirection"  id = "rdTemplateId">
                                        <f:selectItem itemLabel="#{item.templateName}"  itemValue="#{item.templateId}"/>
                                    </h:selectOneRadio>

                                </ui:repeat>

      

Actually I want to create one radio button with different selectItems in it, which should be from the rows of my table in the database. How to do it?

+2


a source to share


3 answers


You won't be able to do this with a JSF component out of the box. However, it is quite easy to implement a custom renderer to accomplish what you need. I would suggest dropping the image url in the SelectItem description field as this is almost never used. Then, in your renderer, just put that value in the IMG tag.



I wrote a bit about custom renderer for selectboxes here - should be an identical process for you.

+1


a source


It looks like you need more <f:selectItems>

.

<h:dataTable value="#{bean.items}" var="#{item}">
    <h:column>
        <h:selectOneRadio value="#{item.selectedTemplate}">
            <f:selectItems value="#{bean.availableTemplates}" />
        </h:selectOneRadio>
    </h:column>
    ...

      



You can transfer it with SelectItem[]

, List<SelectItem>

or Map<Object, String>

.

+1


a source


<t:selectOneRadio>

supports layout="spread"

so you can distribute individual parameter buttons from the same group.

0


a source







All Articles