如何根据当前页面在CQ对话框中配置rootPath

时间:2014-02-28 12:00:43

标签: extjs cq5

我有以下CQ dialog.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="cq:TabPanel"
    activeTab="{Long}0" title="mContactConnect_dialogtitle" headerAsText="true"
    xtype="tabpanel">
    <items jcr:primaryType="cq:WidgetCollection">
        <tab1 jcr:primaryType="cq:Widget" anchor="100%" title="myTitle"
            xtype="panel">
            <items jcr:primaryType="cq:WidgetCollection">
                <subheadline jcr:primaryType="cq:Widget" fieldLabel="subheadline_label"
                    name="./subheadline" maxLength="80" xtype="textfield"/>
                <text jcr:primaryType="cq:Widget" fieldLabel="text_label" name="./text"
                    maxLength="150" xtype="textfield"/>
                <reference jcr:primaryType="cq:Widget" fieldLabel="reference_label"
                    name="./reference" forceSelection="true" xtype="pathfield" rootPath ="/content" />
            </items>
        </tab1>
    </items>
</jcr:root>

现在我想在当前页面上引用某些rootPath depnding。 为此,我将PathField扩展如下:

myExtendedRootPath = CQ.Ext.extend(CQ.Ext.emptyFn, {
    init : function(widget) {
        var currentPath;
        var siteAdmin = CQ.Ext.getCmp("cq-siteadmin");

        if (siteAdmin) {
            currentPath = siteAdmin.getSelectedPages().shift().id;
        } else {CQ.Ext.
            currentPath = CQ.utils.WCM.getPagePath();
        }

        if (currentPath =="page1") {
            widget.treeRoot.name = "content/page1";
        }
        else if (currentPath =="page2") {
            widget.treeRoot.name = "content/page2";
        }
    }
});

CQ.Ext.reg("myExtendedRootPath", myExtendedRootPath.init());

我跟随firebug进行函数调用。为此我在行init : function(widget) {上设置了断点。当我前进时,steppointer跳转到最后一行CQ.Ext.reg...

为什么init功能没有调用?

2 个答案:

答案 0 :(得分:3)

  1. 将创建的对象注册为插件。将最后一行替换为:

    CQ.Ext.ComponentMgr.registerPlugin('myExtendedRootPath', myExtendedRootPath);
    
  2. 将注册的插件添加到reference对话框字段:

    <reference
        jcr:primaryType="cq:Widget"
        fieldLabel="reference_label"
        name="./reference"
        forceSelection="true"
        xtype="pathfield"
        rootPath ="/content"
        plugins="myExtendedRootPath" />
    
  3. 修复语法错误(意外CQ.Ext.):

    if (siteAdmin) {
        currentPath = siteAdmin.getSelectedPages().shift().id;
    } else {CQ.Ext. // <-- here
        currentPath = CQ.utils.WCM.getPagePath();
    }
    
  4. (可选)查找工作示例here

答案 1 :(得分:0)

这适用于所有可能有兴趣动态设置路径域组件的defaultValue的人。这有助于我将值设置为当前页面路径:

(按照上面提到的插件src代码)。然后,使用:

widget.setValue(cq.utils.WCM.getPagePath()).

有趣的是,我必须实际手动定义一个&#39; defaultValue&#39;在上面的行成功运行之前的dialog.xml中的字段!奇怪..所以我的对话框看起来如下:

<reference
    jcr:primaryType="cq:Widget"
    fieldLabel="reference_label"
    name="./reference"
    forceSelection="true"
    xtype="pathfield"
    defaultValue="/content/any/random/string"
    plugins="myExtendedRootPath" />