当 p:messages 更新并且出现(错误)消息时,将其滚动到视图中 [英] Scroll p:messages into view when it is updated and (error) messages are present

查看:62
本文介绍了当 p:messages 更新并且出现(错误)消息时,将其滚动到视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 PrimeFaces 消息,我希望在呈现 p:messages 时我的整个页面都滚动到顶部.

I am working with PrimeFaces messages, I want my whole page to scroll to top when p:messages is rendered.

推荐答案

已弃用 PrimeFaces <6.2

在您的支持 bean(产生消息的 bean)中,您应该知道何时渲染 p:message.如果是这样,只需执行此:

In you backing bean (that one which produces the messages), you should know when you render a p:message. If so simply execute this:

RequestContext.getCurrentInstance().execute("window.scrollTo(0,0);");

更新:

使用 较新的 PrimeFaces 版本 (>= 6.2),该方法在客户端执行 Javascript 是(通过使用 xy 坐标):

With the newer PrimeFaces versions (>= 6.2), the approach to execute Javascript on the client side is (by using x and y coordinates):

PrimeFaces instance = PrimeFaces.current();
instance.execute("window.scrollTo(0,0);");

要滚动到元素,请使用元素的 clientId:

To scroll to an element use the element's clientId:

PrimeFaces instance = PrimeFaces.current();
instance.scrollTo("myElementsClientId");

在此处查找更多信息:

这篇关于当 p:messages 更新并且出现(错误)消息时,将其滚动到视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆