Primefaces

does not disappear after another Ajax request

后端 未结 2 832
时光说笑
时光说笑 2020-12-11 06:53

Let\'s say I have some tooltips in my . When I change the page of dataTable and while another page laods, I move mouse on any to

相关标签:
2条回答
  • 2020-12-11 07:04

    This looks like a PrimeFaces bug, but you can work around it by hiding tooltips on pagination events via JS.

    <p:dataTable value="#{bean.val}" var="row" rowIndexVar="rowIndex" rows="10" paginator="true">
        <p:ajax event="page" oncomplete="hideTooltips();" />
    
        <p:column>
            <h:outputText id="text" value="#{row}" />
            <!--
                since p:tooltip is located inside an iterative component (p:dataTable), we can't
                just define a static widgetVar value, because there will be a widget instance for
                each iteration, and each instance must have a unique widgetVar value, so we'll
                use rowIndex to achieve that
            -->
            <p:tooltip widgetVar="textTipVar#{rowIndex}" for="text" value="Tip" />
        </p:column>
    </p:dataTable>
    <script>
        function hideTooltips() {
            /*
                we've defined a bunch of widgetVars with a dynamic name, so we'll iterate over
                all widgets on the page and find the ones we need by looking for a known
                widgetVar prefix
            */
            for (var w in PrimeFaces.widgets) {
                if (w.indexOf('textTipVar') === 0) {
                    PrimeFaces.widgets[w]._hide();
                }
            }
        }
    </script>
    

    This uses an undocumented Tooltip widget method _hide, keep that in mind when updating to another PrimeFaces version, e.g. the method's name could change. The PrimeFaces.widgets object is undocumented too.

    0 讨论(0)
  • 2020-12-11 07:08

    Incase anybody else struggles with this, I think I found a solution worth trying. In my case, I had a tool tip that showed when I hovered over a commandButton but if I clicked it it would run an ajax request and return, update a component and finish but the tooltip would still remain. This is what I did to fix it.

    <p:tooltip id="saveDeleteTooltip" globalSelector="[data-tooltip]" position="top" hideEvent="mouseleave click"/>
    

    Supply two events for the hideEvent attribute and seems to recognize and use both. The first is for normal mouseout but the second does fire when I click on my commandButtons it does hide the tooltip like it was supposed to do.

    0 讨论(0)
提交回复
热议问题