在另一个Ajax请求之后,Primefaces 不会消失(Primefaces does not disappear after another Ajax request)

编程入门 行业动态 更新时间:2024-10-26 23:28:27
在另一个Ajax请求之后,Primefaces 不会消失(Primefaces does not disappear after another Ajax request)

假设我的<p:dataTable>有一些工具提示。 当我更改dataTable的页面而另一个页面运行时,我在任何工具提示上移动鼠标 - 它显示出来,但是在加载另一个页面后,工具提示永远不会消失..我试图使用p:ajax , p:remoteCommand来更新它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的bug,但你可以通过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>

这使用了一个未记录的Tooltip小部件方法_hide ,在更新到另一个PrimeFaces版本时请记住这一点,例如方法的名称可能会改变。 PrimeFaces.widgets对象也没有记录。

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.

更多推荐

提示,工具,page,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-07-05 01:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Primefaces   Ajax   request   disappear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!