例如,f:selectItems
组件在某些版本的JSF中不支持title属性。
是否可以使用JSFC替换纯HTML对应的JSF组件并执行类似的操作?
<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
答案 0 :(得分:10)
是否可以使用JSFC替换纯HTML对应的JSF组件,并执行类似这样的操作
不。最终,具有jsfc
属性的此类HTML元素将转换为JSF组件树中的真正JSF组件,并且仅将解析相关组件所支持的属性并将其设置为组件属性。 title
属性不在UISelectItem
组件的受支持属性中。我不确定你的意思是什么&#34;某些版本的JSF&#34;。标准的JSF API已经不能支持它了。 JSF spec issue 529描述了这个缺点,目前仍然是开放的。
如果您正在使用JSF 2.2,请使用passthrough属性。您只需要<f:selectItems>
替换<c:forEach><f:selectItem>
,另请参阅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>
的自定义渲染器。
在创建自定义渲染器时,您可以使用description
类的未使用的(!)UISelectItem
属性。我之前就针对<p:selectManyCheckbox>
:Primefaces tooltip for p:selectManyCheckbox的类似问题做出了回答。
<f:selectItems ... var="item" itemDescription="#{item.tooltip}" />
注意到应该为<h:selectOneMenu>
创建自定义渲染器很痛苦,特别是如果您打算独立于JSF实现。从理论上讲,自定义ResponseWriter
应该可以捕捉到这一点,但不幸的是,<h:selectOneMenu>
只在撰写<option>
而不是相关的UISelectItem
时自行传递。
答案 1 :(得分:0)
就我而言(JSF 2.2 / Mojarra 2.2.14),itemDescription 开箱即用。即:
<c:forEach items="#{bean.items}" var="item">
<f:selectItem itemValue="#{item}" itemLabel="#{item}" itemDescription="#{item.tooltip}" />
</c:forEach>