Primefaces <p:tooltip>在另一个 Ajax 请求后不会消失 [英] Primefaces <p:tooltip> does not disappear after another Ajax request
问题描述
假设我的
中有一些工具提示.当我更改 dataTable
的页面并且另一个页面加载时,我将鼠标移到任何工具提示上 - 它会显示,但在其他页面加载后工具提示永远不会消失..我试图更新这个, 使用 p:ajax
, p:remoteCommand
但没有任何帮助,实际上这使得另一个 Ajax
请求和工具提示也卡住了.只有整页重新加载 F5
有效.
Let's say I have some tooltips in my <p:dataTable>
.
When I change the page of dataTable
and while another page laods, I move mouse on any tooltip - it shows up, but after the other page is loaded tooltip never disappears.. I've tried to update this, using p:ajax
, p:remoteCommand
but nothing helps, actually this made another Ajax
request and tooltips also stucked. Only full page reload F5
works.
有人遇到过这样的问题吗?非常感谢您的帮助!
Has anyone encountered with such problem? Thanks a lot for your help!
推荐答案
这看起来像是 PrimeFaces 的错误,但您可以通过 JS 隐藏分页事件的工具提示来解决它.
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>
这使用了一个未记录的工具提示小部件方法 _hide
,在更新到另一个 PrimeFaces 版本时请记住这一点,例如方法的名称可能会改变.PrimeFaces.widgets
对象也没有记录.
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.
更新.正如 russellelbert 在评论中指出的那样,从 PrimeFaces 7.0 开始,该方法的名称只是 hide
- 没有下划线.
此外,从 PrimeFaces 10.0 开始,PrimeFaces.widgets
和 Tooltip#hide
都是已记录的客户端 API 的一部分.
Update. As russellelbert points out in comments, the method's name is just hide
since PrimeFaces 7.0 - no underscore.
Also since PrimeFaces 10.0 both PrimeFaces.widgets
and Tooltip#hide
are part of documented Client API.
这篇关于Primefaces <p:tooltip>在另一个 Ajax 请求后不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!