ToolTip for each SelectOneMenu Items in jsf

前端 未结 2 1592
梦毁少年i
梦毁少年i 2021-01-21 18:00

My requirement is to provide a tooltip for every option in the SelectOneMenu because label of option is so large that it\'s not possible to provide suc

相关标签:
2条回答
  • 2021-01-21 18:29

    If you are using a list of "javax.faces.model.SelectItem" you can pass the description attribute to show a tooltip for each and every option.

    0 讨论(0)
  • 2021-01-21 18:32

    You can use javascript. Assume your selectOneMenu as below.

    <h:form id="form1">
        <h:selectOneMenu id="combo1">
            <f:selectItem itemLabel="First Label"/>
            <f:selectItem itemLabel="Second Label"/>
            <f:selectItem itemLabel="Third Label"/>
        </h:selectOneMenu>
    </h:form>
    

    Add this script at the top of your page.

    <script>
        window.onload = function() {
             var options = document.getElementById("form1:combo1").options;
             for(var i = 0; i &lt; options.length; i++) {
                 options[i].title = options[i].innerHTML;
             }
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题