Showing and clearing global error messages using javascript

UI Components for JSF
Post Reply
primefacesuser222
Posts: 1
Joined: 20 Jan 2023, 16:44

26 Jul 2023, 17:38

Hi Team

From javascript, I would like to know what the right way is to show messages. So far I've found this:

PF('globalMessages').appendMessage({"summary":"summary goes here",
"detail":"detail goes here",
"severity":"error"})

<p:messages id="myMsg" widgetVar="globalMessages"></p:messages>

The only problem is that every time and call appendMessage it adds a item in the page.

Is there any way to clear the messages? like PF('globalMessages').clearMessages();

Note: I would like to do this using only javascript, In the client side, our page is calling an external rest API which does not trigger any backend request to our server.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

27 Jul 2023, 15:20

you have to remove those HTML nodes via jquery currently, as there is no util function.

I created a feature request: https://github.com/primefaces/primefaces/issues/10398
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

28 Jul 2023, 19:11

here is a MonkeyPatch you can use right now.

Code: Select all

if (PrimeFaces.widget.Messages) {
    PrimeFaces.widget.Messages.prototype.clearMessages = function() {
        this.jq.children().remove();
    }
}
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 91 guests