ToolTip for each SelectOneMenu Items in jsf

久未见 提交于 2019-12-04 04:55:49

问题


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 such a large size SelectOneMenu .So the label is cutting. Thats why i need tooltip to show the whole value on mouse over of the options in the SelectOneMenu .

Any ideas will be appreciated.


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/8634563/tooltip-for-each-selectonemenu-items-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!