问题描述
我有一些元素列表,这些元素会生成我的<h:selectOneRadio>
项:
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>
我希望接下来每个元素显示值为#{c.id}
的<h:outputText>
,以便在每一行上是我的radioButton元素,然后在其后是一些文本框.我该怎么做 ?
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 ?
我尝试过类似的事情:
<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>
但是它会在最后一个outputText之后取消播放所有单选按钮.
But it deisplays all radioButtons after last outputText.
我想要类似下面的屏幕截图.例如,如果右边是ID,则可以对其进行加密和解密.
I want something like the below screenshot. When right part is for example IDs, then it can be encrypted and decrypted.
推荐答案
只需将其放在商品标签中即可.
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}"
如果必要,您可以使用HTML,因此,请仅注意.
You can if necessary use HTML like so, you should only beware of XSS attack hole in the surname.
itemlabel="#{c.surname} <strong>#{c.id}<strong>" itemEscaped="false"
或者,如果您实际上希望将它们包含在生成的<label>
之外,请使用第三方组件库.即<h:selectOneRadio>
不支持此功能.例如,战斧的<t:selectOneRadio>
为此具有一个layout="spread"
属性.
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.
- Radio buttons in different parts of the page
- <h:selectOneRadio> renders table element, how to avoid this?
无关与具体问题无关,您不需要<c:forEach>
.太笨拙了.只需使用<f:selectItems var>
.这是自JSF 2.0以来的新功能,也许您过多地关注了古老的JSF 1.x目标资源.
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>
另请参见:
- 我们的
selectOneMenu
Wiki页面 - Our
selectOneMenu
wiki page
See also:
这篇关于如何显示h:selectOneRadio项目附近的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!