MonkeyPatching:PrimeFaces小部件扩展/覆盖 [英] MonkeyPatching: PrimeFaces widgets extend/override

查看:88
本文介绍了MonkeyPatching:PrimeFaces小部件扩展/覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用(工作正常)

I'm currently using (it's working fine)

PrimeFaces.widget.OverlayPanel.prototype._old_init = PrimeFaces.widget.OverlayPanel.prototype.init;
PrimeFaces.widget.OverlayPanel.prototype.init = function(cfg) 
{
    this._old_init(cfg);
    this.align();
}

但是我想使用更具可读性和"jQuery-ish"的功能,例如完全发明的不现实代码:

but I'd like to use something more readable and 'jQuery-ish' like this completely invented unrealistic code:

PrimeFaces.widget.OverlayPanel.patch(
{
    init: function(cfg) 
    {
        super.init(cfg);
        this.align();
    },

    show: function()
    {
        console.log('blah blah blah');
        super.show();
    }
});

我尝试了PrimeFaces.widget.Xxx.extend({...}),但是在这种情况下,我无法访问super方法.

I tried PrimeFaces.widget.Xxx.extend({...}) but in this case I have no access to super methods.

请记住,我对Java语言完全不了解

谢谢

推荐答案

我已经实现:

if(PrimeFaces.widget.OverlayPanel)
{
    PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.OverlayPanel.extend(
    {
        init: function(cfg) 
        {
            this._super(cfg);
            this.align();
        },

        show: function()
        {
            console.log('blah blah blah');
            this._super();
        }
    });
};

它存储在里面

  • 应用
    • 资源
      • js
        • pf-patches.js
        • app
          • resources
            • js
              • pf-patches.js

              并在全局模板中使用:

              <!DOCTYPE html>
              <html lang="#{userBean.locale.language}" xmlns="http://www.w3.org/1999/xhtml" 
                  xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html"
                  xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:cc="http://xmlns.jcp.org/jsf/composite"
                  xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
                  xmlns:p="http://primefaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions"
                  xmlns:o="http://omnifaces.org/ui" xmlns:of="http://omnifaces.org/functions"
                  xmlns:s="http://shapeitalia.com/jsf2" xmlns:sc="http://xmlns.jcp.org/jsf/composite/shape"
                  xmlns:e="http://java.sun.com/jsf/composite/cc" xmlns:et="http://shapeitalia.com/edea2"
                  xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
              
              <f:view locale="#{userBean.locale}" contentType="text/html">
                  <h:head>
                      <f:facet name="first">
                          <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
                          <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
                          <title><ui:insert name="title">#{navigatorBean.viewTitle}</ui:insert></title>
                          <link rel="shortcut icon" type="image/x-icon" href="#{resource['favicon/favicon.ico']}" />
                      </f:facet>
              
                      <f:facet name="last">
              ==========> <h:outputScript name="js/pf-patches.js" /> <==========
                          <h:outputScript library="omnifaces" name="fixviewstate.js" />
                      </f:facet>
                  </h:head>
              
                  <h:body>
                      <h:outputStylesheet name="theme/custom.css" />
                      <h:outputStylesheet name="theme/other-icons.css" />
              
                      ...
              

              这篇关于MonkeyPatching:PrimeFaces小部件扩展/覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆