HTML 5下拉列表和JSF 2.2 [英] HTML 5 dropdown and JSF 2.2
问题描述
我正在尝试向JSF托管bean发送< select>
值,但我不知道如何创建它。
我的代码是:
I´m trying to send a <select>
value to a JSF managed bean but I don´t know how to make it.
My code is:
<select id="cb-frentes" required="required" jsf:value="#{checkstyleBean.frente}">
<option value=""/>
<ui:repeat var="frente" value="#{appBean.frentes}">
<option value="#{frente}" label="#{frente}"/>
</ui:repeat>
</select>
它不起作用。当我调用我的操作方法时, frente
属性的值总是 null
。
It does not work. The value of frente
attribute is always null
, when I invoke my action method.
如何进行此绑定?
推荐答案
< option>
元素默认情况下不会被识别为 passthrough元素。它没有在 Java EE教程第8.9章表8.4中列出HTML5友好标记'。
The <option>
element is by default not recognized as a passthrough element. It's not listed in table 8.4 of Java EE tutorial chapter 8.9 'HTML5-Friendly Markup'.
您需要明确告知底层的JSF组件。您可以使用 jsfc
属性来执行此操作,这在Java EE 7教程中未提及(可能因为它是Facelets的一部分,视图技术,而不是JSF) 。
You'd need to explicitly tell the underlying JSF component. You can do that using the jsfc
attribute, which is surprisingly not mentioned in the Java EE 7 tutorial (perhaps because it's part of Facelets, the view technology, and not of JSF).
<select id="cb-frentes" required="required" size="1" jsf:value="#{checkstyleBean.frente}">
<option value="#{null}" jsfc="f:selectItem" />
<ui:repeat value="#{appBean.frentes}" var="frente" jsfc="f:selectItems">
<option value="#{frente}">#{frente}</option>
</ui:repeat>
</select>
请注意,我将第一个选项的值固定为显式#{ null}
,我修复了设置选项标签的错误方法。此外,我还将 size =1
添加到< select>
,否则它默认呈现为列表框而不是下拉列表。
Note that I fixed the value of the 1st option to be explicitly #{null}
, and that I fixed the incorrect way of setting the option label. Further I also added size="1"
to the <select>
, otherwise it's by default rendered as a listbox instead of a dropdown.
这篇关于HTML 5下拉列表和JSF 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!