【问题标题】:How to configure a rootPath in CQ Dialog depending on current page如何根据当前页面在 CQ Dialog 中配置 rootPath
【发布时间】:2014-02-28 12:00:42
【问题描述】:

我有以下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>

现在我想引用当前页面上的某些根路径。 为此,我将 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 函数不调用?

【问题讨论】:

  • 不确定这有多大帮助,但您可以将 id 作为 xml 属性添加到路径字段,然后尝试使用 CQ.Ext.getCmp("id value added to the pathfield").setRootPath 访问它("这条路径将是动态路径");将此添加到从 jsp 加载的 js 文件中
  • 一开始,您使用的是dmyExtendedRootPath,之后使用的是myExtendedRootPath——这是一个错字吗?

标签: extjs aem


【解决方案1】:
  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();
    }
    

(可选)找到一个工作示例here

【讨论】:

    【解决方案2】:

    这适用于所有可能对动态设置路径字段组件的 defaultValue 感兴趣的人。这对我来说可以将值设置为当前页面路径:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 2012-12-06
      • 1970-01-01
      • 2016-10-25
      • 2013-04-04
      • 1970-01-01
      • 2019-05-01
      相关资源
      最近更新 更多