是否可以在 CQ 对话框侦听器中获取页面属性

Is it possible to get Page Properties inside CQ dialog listener

我有一个页面在 /content/admin/mycomp-test/testpage/jcr:内容

属性

name : validated
type : boolean
value : true

是否可以在 CQ 对话框中获取上述 属性 值 我尝试了以下代码,但它不起作用。

<listeners jcr:primaryType="nt:unstructured"
               beforesubmit="function(dialog) {

                var compPath = dialog.path;

                Resource res= resourceResolver.getResource(compPath);

                Node node = res.adaptTo(Node.class);

                var prop= node.getProperty('validated').getValue().getString(); 



                CQ.Ext.Msg.alert('valieded : ' + prop);
                    return false;

        }" />
}

以下代码将为您提供所需的信息:

<listeners jcr:primaryType="nt:unstructured"
    beforesubmit="function(dialog) {
        var properties = CQ.shared.HTTP.eval(CQ.shared.HTTP.noCaching(dialog.path + '.-1.json'));
        var validated = properties.validated;

        CQ.Ext.Msg.alert('Validated: ' + validated);

    }" />
}

在我看来,最好将这种 JavaScript 保存在外部文件中,该文件将包含在仅在编辑模式下显示的 clientlib 中。然后您可以从对话框中调用该方法。例如:

beforesubmit="function(dialog){ foo.bar.baz(dialog); }"

如果您要验证用户输入,有更好的方法。探索 Widgets API documentation.