我有一个允许用户在指定路径中选择资产的组件。在用户选择资产并单击“确定”后,我从资产的属性中获取lat / long并将其绘制在Google地图上。这很好但现在我希望用户能够选择多个资源,以便可以在地图上放置多个标记。
目前,作者选择资产的对话框如下所示
一旦选择了资产并点击了OK,我的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>
答案 0 :(得分:2)
有没有办法修改代码,以便用户可以选择 多个资产,而不仅仅是能够选择一个?
是。您可以考虑将“multifield
”与pathfield
一起使用,而不是仅使用pathfield
“。
asset-reference (xtype = multifield , name= ./fileReference)
fieldConfig (xtype = pathfield)
我可以访问Java类中的所有选定资产吗?
在你的java类中,你不需要使用getProperties().get("fileReference", String.class);
,而是需要使用getProperties()。get(“fileReference”,String [] .class);
Multifield将值存储为String数组而不是字符串。