2015-06-30 64 views
2

我试图将cq:listenerhttps://docs.adobe.com/docs/en/cq/5-5/developing/components/edit_config.html#cq:listeners添加到我的组件,以便在选择资源并单击“确定”后,页面刷新。如何将cq:listener添加到组件

这是组件在我选择资产并点击确定的屏幕上查找的方式。

enter image description here

在我的代码中,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" 
    jcr:primaryType="cq:Dialog" 
    xtype="dialog"> 
    <items 
     jcr:primaryType="cq:Widget" 
     xtype="tabpanel"> 
     <items jcr:primaryType="cq:WidgetCollection"> 
      <tab1 
       jcr:primaryType="cq:Panel" 
       title="Tab"> 
        <items 
         jcr:primaryType="cq:WidgetCollection"> 
          <asset-reference 
           jcr:primaryType="cq:Widget" 
           fieldLabel="Foo Bar:" 
           fieldDescription="Select the asset under /content/dam/foo-sync" 
           name="./fileReference" 
           xtype="pathfield" 
           rootPath="/content/dam/evernote-sync"/> 
        </items> 
      </tab1> 
     </items> 
    </items> 
</jcr:root> 

_cq_editConfig.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:EditConfig"> 
    <cq:dropTargets jcr:primaryType="nt:unstructured"> 
     <fileReference 
      jcr:primaryType="cq:DropTargetConfig" 
      accept="[text/.*]" 
      groups="[media]" 
      propertyName="./fileReference"/> 
    </cq:dropTargets> 
</jcr:root> 

回答

2

为孩子创建名为cq:listeners和类型节点cq:EditListenersConfigcq:EditConfig节点。将属性afteredit添加到新创建的值为REFRESH_PAGE的节点,以便在组件编辑后刷新页面。默认情况下,该值为REFRESH_SELF,因此只有组件在编辑后刷新,而不是整个页面。

_cq_editConfig.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:EditConfig"> 
    <cq:listeners jcr:primaryType="cq:EditListenersConfig" 
     afteredit="REFRESH_PAGE"/> 
    <cq:dropTargets jcr:primaryType="nt:unstructured"> 
     <fileReference 
      jcr:primaryType="cq:DropTargetConfig" 
      accept="[text/.*]" 
      groups="[media]" 
      propertyName="./fileReference"/> 
    </cq:dropTargets> 
</jcr:root> 

更多细节可以在link mentioned in the question本身被发现。

1

您可以尝试在你的_cq_editConfig.xml以下

<?xml version="1.0" encoding="UTF-8"?> 
 
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" 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:EditConfig"> 
 
\t <cq:listeners 
 
\t  jcr:primaryType="cq:EditListenersConfig" 
 
\t  afterdelete="REFRESH_PAGE" 
 
\t  afteredit="REFRESH_PAGE" 
 
\t  afterinsert="REFRESH_PAGE" 
 
\t  afterMove="REFRESH_PAGE"/> 
 
</jcr:root>