tags:

views:

66

answers:

3

Hello, I am trying to create a grooup of h:selectOneRadio but ui:repeat gives it different id 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 a single radio button with different selectItems in it which should be from the rows of my table in database. How do i do this?

A: 

<t:selectOneRadio> supports layout="spread" so that you can spread the individual option buttons from a single group.

Bozho
This is by the way not going to be easy in a loop inside a datatable.
BalusC
perhaps I've misunderstood the question. At first I thought of f:selectItems, but then something sparked about having a table and a radio on each row. I've had exactly the same scenario and t:selectOneRadio did it easily. Let's see what he actually wants :)
Bozho
Hi Bozho, you can imagine my requirement to be something of "h:selectOneRadio inside datatable". I read BalusC's article and implemented it. It's working but it's not so easy to do. My requirement is :-say suppose i have three rows in my table as "Apple, Mango, Banana" and i have their three images as "apple.jpg,,mango.jpg,banana.jpg". I want the interface to be like :- Apple photo diplayed, then apple option, Banana photo displayed then banana photo displayed and then mango photo displayed and mango option.". These behave as a group, mean i can only select one of them.
Ankit Rathod
And i cannot use f:selectItems because inside it i can't put a <h:graphicImage> tag. If i am still not clear please let me know.
Ankit Rathod
A: 

It more sounds like that you rather need <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 feed it with a SelectItem[], List<SelectItem> or a Map<Object, String>.

BalusC
Hi BalusC, WHat if i want to display graphic image along with <h:selectOneRadio>? I tried putting h:graphicImage inside f:selectItems tag but it didn't work.
Ankit Rathod
Either grab CSS/JS, or use another component (RichFaces has one where this is possible, if I recall correctly), or override the renderer.
BalusC
+1  A: 

You won't be able to do this with a JSF component out-of-the-box. However it's fairly easy to implement a custom renderer to accomplish what you're after. I would suggest dumping an image URL into the SelectItem description field as this is almost never used. Then in your renderer just place this value into an IMG tag.

I've written a little about a custom renderer for selectboxes here - should be an identical process for you.

Damo