Is it possible to add a "title" attribute to the tag in JSF, for example:
<f:selectItems value="#{foo.fooList}" title="{foo.fooDescription}"/>
Generated HTML:
<select>
<option value="foo1" title="description1">foo ex1</option>
<option value="foo2" title="description2">foo ex2</option>
</select>
I don't have an elegant solution, but it can be done. I'm assuming JSF 2+ & Facelets VDL.
For a managed 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;
}
}
You can use JavaScript to set the title
attribute on the DOM node:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With