Abdennour TOUMI
Abdennour TOUMI

Reputation: 93203

Add message to p:growl using Javascript

I want to display a growl in client-side using Javascript.

I mean this UI-component:

enter image description here

I found this thread , However , I can't find an object called :topBar

Known also that using:

grep -rl to find text in files leads to discover this JS :

/**
 * PrimeFaces NotificationBar Widget
 */
PrimeFaces.widget.NotificationBar = PrimeFaces.widget.BaseWidget.extend({

    init: function(cfg) {
        this._super(cfg);

        var _self = this;

        //relocate
        this.jq.css(this.cfg.position, '0').appendTo($('body'));

        //display initially
        if(this.cfg.autoDisplay) {
            $(this.jq).css('display','block')
        }

        //bind events
        this.jq.children('.ui-notificationbar-close').click(function() {
            _self.hide();
        });
    },

    show: function() {
        if(this.cfg.effect === 'slide')
            $(this.jq).slideDown(this.cfg.effect);
        else if(this.cfg.effect === 'fade')
            $(this.jq).fadeIn(this.cfg.effect);
        else if(this.cfg.effect === 'none')
            $(this.jq).show();
    },

    hide: function() {
        if(this.cfg.effect === 'slide')
            $(this.jq).slideUp(this.cfg.effect);
        else if(this.cfg.effect === 'fade')
            $(this.jq).fadeOut(this.cfg.effect);
        else if(this.cfg.effect === 'none')
            $(this.jq).hide();
    },

    isVisible: function() {
        return this.jq.is(':visible');
    },

    toggle: function() {
        if(this.isVisible())
            this.hide();
        else
            this.show();
    }

});

Upvotes: 13

Views: 15112

Answers (2)

Hatem Alimam
Hatem Alimam

Reputation: 10048

The component you are referring to is Growl, in the client-side it's represented by PrimeFaces.widget.Growl which has renderMessage function to render a single growl message.

Assuming you have already defined a growl component in your page with a widgetVar name:

<p:growl widgetVar="growlWV" />

Now in javascript

PF('growlWV').renderMessage({"summary":"summary goes here",
                             "detail":"detail goes here",
                             "severity":"warn"})

The severity are obviously three types :

  • info

info growl

  • warn

warn growl

  • error

error growl

Upvotes: 41

Sergio Soto
Sergio Soto

Reputation: 1

This worked for me with primefaces:

<script type="text/javascript">
    function validateSearch(){
               PF('growlWV').init({'msgs':'"summary":"Select a State Medical Unit or Demographic Capture Date", "severity":"info" ',
                   "life":"9000"})
           }

    }

You can see the methods here: https://searchcode.com/codesearch/view/2686099/

Upvotes: -2

Related Questions