gpt4 book ai didi

jsf - JSF tag custom tooltip attribute

转载 作者:行者123 更新时间:2023-12-04 04:22:41 24 4
gpt4 key购买 nike

是否可以在 JSF 中为标签添加“title”属性,例如:

<f:selectItems value="#{foo.fooList}" title="{foo.fooDescription}"/>

生成的 HTML:

<select>
<option value="foo1" title="description1">foo ex1</option>
<option value="foo2" title="description2">foo ex2</option>
</select>

最佳答案

我没有一个优雅的解决方案,但它可以做到。我假设 JSF 2+ 和 Facelets VDL。

对于托管 bean Foo :

@ManagedBean @RequestScoped
public class Foo {
private List<SelectItem> fooList = Arrays.asList(
new SelectItem("value1", "label1", "description1"),
new SelectItem("value2", "label2", "description2"));

public List<SelectItem> getFooList() {
return fooList;
}
}

您可以使用 JavaScript 设置 title DOM 节点上的属性:

<h:selectOneMenu binding="#{requestScope.fooSelectOne}">
<f:selectItems value="#{foo.fooList}" />
</h:selectOneMenu>
<script>
(function() {
var selectName = '#{requestScope.fooSelectOne.clientId}';
var kids = document.getElementsByName(selectName)[0]
.getElementsByTagName("option");
var index = 0;
<ui:repeat value="#{foo.fooList}" var="_opt">
kids[index++].title = '#{_opt.description}'; //TODO: escape this
</ui:repeat>
}());
</script>

关于jsf - <f :selectItems> JSF tag custom tooltip attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9800807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com