I am working with PrimeFaces messages, I want my whole page to scroll to top when p:messages
is rendered.
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- h:selectOneMenu in p:dataTable doesn't submit
- Use JS/jQuery to scroll a div's content that h
- Jscrollpane - Fires a function when isAtBottom
- PrimeFaces block UI does not work when the compone
相关文章
- SwiftUI automatically scroll to bottom in ScrollVi
- Prevent page navigation on horizontal scroll
- How to let the chrome forget the page scroll posit
- [removed] scrollBy function executed on a div
- Attach scroll event to div with body on() binding
- Add a scrollbar to a <textarea> [duplicate]
- How to override primefaces component api class wit
- Automatically vertically scroll div contents loopi
Assign an ID to your p:message component
Then, in your backing bean call RequestContext.scrollTo method:
in PrimeFaces >= 6.0:
in Primefaces < 6.0:
which is deprecated in PrimeFaces 6.0
Deprecated with PrimeFaces < 6.2
In you backing bean (that one which produces the messages), you should know when you render a
p:message
. If so simply execute this:Update:
With the newer PrimeFaces versions (>= 6.2), the approach to execute Javascript on the client side is (by using x and y coordinates):
To scroll to an element use the element's clientId:
Find more information here:
There are valid answers already that show how to scroll to the
p:messages
component, but they all require you to execute code in a backing bean. This requires you to do / call the same in each action. None show how to scroll to the messages component when it is rendered (updated).You can implement a phase listener and check messages are present and if the messages component's
clientId
is present in thePartialViewContext
renderIds
:Your listener can look something like this:
Make sure to register it in your
faces-config.xml
:Tested with XHTML:
To check for global messages, use:
See also:
Lets say that your button is causing the messages to appear.
XHTML
javascript
Hope this helps.