【问题标题】:Is there a way to select multiple assets in a component?有没有办法在一个组件中选择多个资产?
【发布时间】:2015-06-30 03:17:08
【问题描述】:

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

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

一旦选择资产并单击确定,我的 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>

【问题讨论】:

    标签: java osgi aem sightly


    【解决方案1】:

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

    是的。您可以考虑将“multifield”与pathfield 一起使用,而不是仅使用pathfield”。

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-06-11
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多