ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-MonkeyPatching:PrimeFaces小部件扩展/覆盖

2019-10-27 04:43:00  阅读:178  来源: 互联网

标签:jsf primefaces monkeypatching javascript jquery


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

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”的功能,例如完全发明的不现实代码:

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({…}),但在这种情况下,我无法访问超级方法.

请记住我对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

它在全局模板中使用:

<!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" />

        ...

标签:jsf,primefaces,monkeypatching,javascript,jquery
来源: https://codeday.me/bug/20191027/1942156.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有