在 JSF 中将单选按钮分解为列
当我使用 h:selectOneRadio 并提供列表中的值列表时 整个单选按钮部分显示为一个完整的列表。 我需要将其排列为 3 列。 我尝试过
<h:panelGrid id="radioGrid" columns="3">
<h:selectOneRadio id="radio1" value="#{bean.var}">
<f:selectItems id="rval" value="#{bean.list}"/>
</h:selectOneRadio>
</h:panelGrid>
但渲染部分没有任何区别。 它没有分成列。 我究竟做错了什么?
When I am using h:selectOneRadio and supplying the list of values in a list as
the entire radio button section is exposed as a single unbroken list. I need to arrange it in 3 columns. I have tried giving
<h:panelGrid id="radioGrid" columns="3">
<h:selectOneRadio id="radio1" value="#{bean.var}">
<f:selectItems id="rval" value="#{bean.list}"/>
</h:selectOneRadio>
</h:panelGrid>
But there is no difference in the rendered section. Its not broken up into columns. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经调整了 Damo 给出的代码,以使用 h:selectOneRadio 而不是 h:selectManycheckbox。 要使其正常工作,您需要在 faces-config.xml 中注册它:
要编译它,您还需要 JSF 实现(通常可以在应用程序服务器中的某种 jsf-impl.jar 中找到)。
该代码在 div 中输出单选按钮,而不是表格。 然后,您可以使用 CSS 来设置您想要的样式。 我建议为 checkboxDiv 和内部 div 提供固定宽度,然后将内部 div 显示为内联块:
这应该给出您正在查找的 3 列
代码:
I've adapted the code given by Damo, to work with h:selectOneRadio instead of h:selectManycheckbox. To get it working you will need to register it in your faces-config.xml, with:
To compile it, you will also need the JSF implementation (typically found in some sort of jsf-impl.jar in you app server).
The code outputs the radiobuttons in divs, instead of a table. You can then use CSS to style them however you would like. I would suggest giving a fixed width to the checkboxDiv and inner divs, and then having the inner divs display as inline blocks:
Which should give the 3 columns you are looking for
The code:
h:panelGrid 仅包含一个子项 (ah:selectOneRadio),因此它只会呈现一列。 h:selectOneRadio 也呈现 HTML 表格。 它的渲染器仅提供两种布局(lineDirection 和 pageDirection)。
您可以选择
The h:panelGrid contains only one child (a h:selectOneRadio), so it will only ever render one column. The h:selectOneRadio renders a HTML table too. Its renderer only offers two layouts (lineDirection and pageDirection).
You have a few options
战斧有魔法! 一探究竟!
http://wiki.apache.org/myfaces/Display_Radio_Buttons_In_Columns
Tomahawk does the magic! Check it out!
http://wiki.apache.org/myfaces/Display_Radio_Buttons_In_Columns