0

我有一个组件允许用户选择指定路径中的资产。用户选择资产并单击“确定”后,我从资产的属性中获取纬度/经度并将其绘制在谷歌地图上。这工作正常,但现在我希望用户能够选择多个资产,以便可以在地图上放置多个标记。

目前,作者选择资产的对话框如下所示

在此处输入图像描述

选择资产并单击“确定”后,我的 java 代码将像这样引用该资产

public class Foo extends WCMUse {
   public void activate() {
      fileReference = getProperties().get("fileReference", String.class);
      ....
   }
}

问题 有没有办法修改代码,使用户可以选择多个资产,而不仅仅是能够选择一个?我可以访问我的 Java 类中的所有选定资产吗?

我的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/foo"/>
                    </items>
            </tab1>
        </items>
    </items>
</jcr:root>

.context.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:Component"
    jcr:title="My Component"
    allowedParents="*/parsys"
    componentGroup="My Components"/>

_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>
4

1 回答 1

2

有没有办法修改代码,以便用户可以选择多个资产,而不仅仅是能够选择一个?

是的。您可以考虑使用 " multifield" withpathfield而不是仅使用pathfield"。

asset-reference (xtype = multifield , name= ./fileReference)
       fieldConfig (xtype = pathfield)

我可以访问我的 Java 类中的所有选定资产吗?

在您的 java 类中,您getProperties().get("fileReference", String.class);需要使用 getProperties().get("fileReference", String[].class);而不是 using

多字段将值存储为字符串数组而不是字符串。

于 2015-06-30T05:10:23.687 回答