【问题标题】:Show growl using Javascript使用 Javascript 显示咆哮
【发布时间】:2014-10-19 08:14:58
【问题描述】:

我想使用 Javascript 在客户端显示咆哮。

我的意思是这个 UI 组件:

我找到了这个thread,但是,我找不到一个名为:topBar的对象

也知道使用:

grep -rl 在文件中查找文本会导致发现这个 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();
    }

});

【问题讨论】:

    标签: javascript jsf primefaces


    【解决方案1】:

    您所指的组件是 Growl,在客户端它由 PrimeFaces.widget.Growl 表示,它具有 renderMessage 函数来呈现单个咆哮消息。

    假设您已经在页面中使用 widgetVar 名称定义了一个咆哮组件:

    <p:growl widgetVar="growlWV" />
    

    现在在javascript中

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

    严重程度明显分为三种:

    • 信息

    • 警告

    • 错误

    【讨论】:

    • 我希望这被正确记录
    • 'PF('growlWV').renderMessage({"summary":"summary goes here"});'此显示严重性类型消息。
    • 有没有办法通过JS清除已有的消息?
    • PF('growlWV').removeAll() 这将删除该咆哮实例中的所有消息。 @SeanCoetzee
    • @HubertGrzeskowiak 这是……在 StackOverflow 上。 ;) ;) ;)
    【解决方案2】:

    这对我使用 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"})
               }
    
        }
    

    你可以在这里查看方法:https://searchcode.com/codesearch/view/2686099/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多