How display something near h:selectOneRadio item?

爱⌒轻易说出口 提交于 2019-12-24 13:09:16

问题


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.


回答1:


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:

  • Radio buttons in different parts of the page
  • <h:selectOneRadio> renders table element, how to avoid this?

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:

  • Our selectOneMenu wiki page


来源:https://stackoverflow.com/questions/14529612/how-display-something-near-hselectoneradio-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!