1

I have some list of elements, that generates my <h:selectOneRadio> items:

<h:selectOneRadio id="list#{cand.id}" value="#{mybean.value}" layout="pageDirection">
    <c:forEach items="#{mybean.list}" var="c">
        <f:selectItem id="first#{c.id}" itemlabel="#{c.surname}" itemValue="#{c.name}" />
    </c:forEach>
</h:selectOneRadio>

I want next each element display <h:outputText> with value #{c.id}, so that at each row will be my radioButton element and next it some textbox. How can I do it ?

I tried something like that:

<h:selectOneRadio id="candidates1#{cand.id}" value="#{candidates.selectedCandidate1}" layout="pageDirection">
    <c:forEach items="#{candidates.c1}" var="cand">
        <td>
            <f:selectItem id="first#{cand.id}" itemlabel="#{cand.surname}" itemValue="#{cand.name}">
                <h:outputText id="c1ShortName#{cand.id}" value="#{cand.id}" />
            </f:selectItem>
        </td>
        <td>
            <h:outputText id="c1ShortName#{cand.id}" value="#{cand.id}" />
        </td>
    </c:forEach>
</h:selectOneRadio>

But it deisplays all radioButtons after last outputText.

I want something like the below screenshot. When right part is for example IDs, then it can be encrypted and decrypted.

enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Aram Gevorgyan
  • 2,175
  • 7
  • 37
  • 57

1 Answers1

3

Just put it in the item label.

itemlabel="#{c.id} #{c.surname}"

Or the other way round, you was not clear on that.

itemlabel="#{c.surname} #{c.id}"

You can if necessary use HTML like so, you should only beware of XSS attack hole in the surname.

itemlabel="#{c.surname} &lt;strong&gt;#{c.id}&lt;strong&gt;" itemEscaped="false"

Or, if you actually want to have them outside the generated <label>, then use a 3rd party component library. This is namely not supported by <h:selectOneRadio>. For example, Tomahawk's <t:selectOneRadio> has a layout="spread" attribute for that.

See also:


Unrelated to the concrete problem, you don't need that <c:forEach>. That's plain clumsy. Just use <f:selectItems var>. This is new since JSF 2.0, perhaps you were focusing too much on ancient JSF 1.x targeted resources.

<h:selectOneRadio ...>
    <f:selectItems value="#{mybean.list}" var="c" 
        itemlabel="#{c.id} #{c.surname}" itemValue="#{c.name}" />
</h:selectOneRadio>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • No, the problem is that, I want to be them seperate. I need them to be in different controls. – Aram Gevorgyan Jan 25 '13 at 20:20
  • That's not possible with ``. I updated the answer. In the future questions, be more clear with what you want to achieve in the final HTML markup, e.g. by supplying an example of the desired HTML output. – BalusC Jan 25 '13 at 20:21
  • So it's impossible doing with MyFaces? – Aram Gevorgyan Jan 25 '13 at 20:24
  • No, that's not possible. The `UISelect` components accept only `UISelectItem(s)` children. Just use `itemlabel="#{c.surname} #{c.id}"`. I don't see why you need to have it in a separate ``. Is it for styling purposes? If so, what exactly is the concrete functional requirement requiring you to use this odd construct? In any case, you can always use HTML in the item label if you set `itemEscaped="false"`. – BalusC Jan 25 '13 at 20:27
  • My current answer still stands. The `` is likely your best bet. – BalusC Jan 25 '13 at 20:36
  • Thanks, I understand, I just answer you why I want them to be in a separate . – Aram Gevorgyan Jan 25 '13 at 20:43