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?
a source to share
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.
a source to share
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>
.
a source to share
<t:selectOneRadio>
supports layout="spread"
so you can distribute individual parameter buttons from the same group.
a source to share