如何将工具提示添加到f:selectItems [英] How to add tooltip to f:selectItems

查看:97
本文介绍了如何将工具提示添加到f:selectItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,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>

这样做,用上面的内容替换后者,我得到了"<f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlPanelGroup" Facelet TagExceptions

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组件,并执行类似的操作

不.最终,具有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,请使用传递属性.您只需将<f:selectItems>替换为<c:forEach><f:selectItem>,另请参见使用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.如果无法升级,则基本上需要<h:selectOneMenu>的自定义渲染器. 创建自定义渲染器时,可以使用UISelectItem类的未使用(!)description属性.我之前针对针对<p:selectManyCheckbox>的类似问题回答了这个问题: p的"Primefaces"工具提示: a>.

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.

<f:selectItems ... var="item" itemDescription="#{item.tooltip}" />

请注意,为<h:selectOneMenu>创建定制渲染器是一件很麻烦的事情,特别是如果您打算独立于JSF实现.从理论上讲,自定义ResponseWriter应该能够捕获此错误,但是不幸的是,<h:selectOneMenu>仅在编写<option>时才通过,而不是有问题的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆