问题描述
例如,f:selectItems
组件在某些版本的 JSF 中不支持 title 属性.
For example the f:selectItems
component doesn't support the title attribute in some versions of JSF.
是否可以使用 JSFC 将 JSF 组件替换为它们的纯 HTML 对应组件并执行类似操作?
Would it be possible to replace JSF Components by their plain HTML counterparts using JSFC and do something like this?
<select jsfc="h:selectOneMenu" value="#{cc.data}">
<option jsfc="f:selectItems" value="${cc.listItems}" var="item" title="#{item.tooltip}"></option>
</select>
代替
<h:selectOneMenu value="#{cc.data}">
<f:selectItems value="#{cc.listItems}" />
</h:selectOneMenu>
完全这样做,用上面的替换后者,我得到 " Parent not an instance of ValueHolder: javax.faces.component.html.HtmlPanelGroup"
Facelet标签异常
Doing exactly so, replacing the latter by the above, I'm getting "<f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlPanelGroup"
Facelet TagExceptions
推荐答案
没有.最终,这种带有 jsfc
属性的 HTML 元素将在 JSF 组件树中变成真正的 JSF 组件,并且仅相关组件支持的属性将被解析和设置为组件属性.title
属性不在 UISelectItem
组件.我不确定某些版本的 JSF"究竟是什么意思.标准 JSF API 一开始就不支持它.JSF 规范问题 529 描述了这个缺点,目前仍处于开放状态.
Nope. Ultimately, such a HTML element with jsfc
attribute will be turned into a true JSF component in the JSF component tree and only the attributes supported by the component in question would be parsed and set as component attribute. The title
attribute isn't among the supported attributes of UISelectItem
component. I'm not sure what exactly you mean with "some versions of JSF". The standard JSF API already doesn't support it in first place. JSF spec issue 529 describes this shortcoming and is currently still open.
如果您使用的是 JSF 2.2,请使用 passthrough 属性.您只需要将 替换为
,另见 在 passtrough 属性中使用 f:selectItems var
If you're using JSF 2.2, make use of passthrough attributes. You only need to replace <f:selectItems>
by <c:forEach><f:selectItem>
, see also Using f:selectItems var in passtrough attribute
<... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<c:forEach value="#{bean.items}" var="item">
<f:selectItem itemValue="#{item}" a:title="#{item.tooltip}" />
</c:forEach>
根据您的问题历史记录,您似乎还没有使用 JSF 2.2.如果不能升级,基本上需要的自定义渲染器.在创建自定义渲染器时,您可以使用
UISelectItem
类的未使用(!) description
属性.我之前在一个针对 <p:selectManyCheckbox>
的类似问题上回答过这个问题:p:selectManyCheckbox 或其他 p:selectMany*/One* 的 Primefaces 工具提示.
Based on your question history you seem to be not using JSF 2.2 yet. If you can't upgrade, you basically need a custom renderer for <h:selectOneMenu>
.While creating the custom renderer, you could make use of the unused(!) description
property of the UISelectItem
class. I've answered this before on a similar question targeted at <p:selectManyCheckbox>
: Primefaces tooltip for p:selectManyCheckbox or other p:selectMany*/One*.
<f:selectItems ... var="item" itemDescription="#{item.tooltip}" />
应该注意的是,为 创建自定义渲染器是一件痛苦的事情,尤其是当您打算独立于 JSF 实现时.理论上,自定义的
ResponseWriter
应该能够捕捉到这一点,但不幸的是, 只有在编写
时才会通过自身code>,而不是有问题的
UISelectItem
.
Noted should be that creating the custom renderer for <h:selectOneMenu>
is a pain, particularly if you intend to be JSF implementation independent. Theoretically, a custom ResponseWriter
should be able to catch this, but unfortunately, the <h:selectOneMenu>
only passes itself when writing <option>
, instead of the UISelectItem
in question.
这篇关于如何将工具提示添加到 f:selectItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!