Search code examples
jqueryprimefacesgrowl

in jQuery overwritten show function makes PrimeFaces growl stay visible


I needed to overwrite the show function for specific elements. This works fine so far. But there is an evil side effect: My growl element stays visible after it shows. There is no log error in the console and the other stuff works fine. It also doesnt stuck anywhere. It just never hides again after it is shown.

Here my jQuery function:

jQuery(function($) {

            jQuery.fn.oldshow = jQuery.fn.show;

            jQuery.fn.show = function() {
                //Use old function
                return jQuery(this).oldshow();
            };
        });

Here the growl element:

  <p:growl id="growl" showDetail="true" />

without the jQuery function it works as expected and hides again.

It would be great to get some tipps or a solution.

I already tried to replace it with:

jQuery(function($) {

            var oldshow = $.fn.show;

            $.fn.show = function(args) {
                var t = $(this);
                return oldshow.apply(t, arguments);
            };
        });

it makes no difference


Solution

  • Overwrite the primefaces function instead of the jquery function

    PrimeFaces.widget.Growl.prototype.show = (function() {
     var oldFunction = PrimeFaces.widget.Growl.prototype.show;
     return function() {
        //some logic
    
        //use old function
        return oldFunction.apply(this, arguments);
     };
    })();