【问题标题】:AEM/CQ Multiple Image ComponentAEM/CQ 多图像组件
【发布时间】:2016-02-23 19:39:27
【问题描述】:

我正在尝试创建一个包含两个图像和一些信息的组件,我创建了对话框,设法创建节点并上传图像。一切正常,但我找不到获取图像路径或渲染它的方法。

这是我目前所拥有的:

<%@ page import="com.day.text.Text,
               com.day.cq.wcm.foundation.Image,
               com.day.cq.commons.Doctype" %>
<%@include file="/apps/platform/aem-core/global/global.jsp"%>

<%
    Image image = new Image(resource, "image1");

    out.println(image);

    image.draw(out);
%>

<h2><%=image.getSrc()%></h2>

这给了我:/content/region-growth/brazil/brazil-poc/pt-br/home/jcr:content/leadmachine-new/image1/file.jpg/1456255696906.jpg 如果我去这个文件夹有一个名为 image1 > file 的节点。图片在那里,如果我尝试使用 crxde 下载它,我可以打开它,所以我相信我的问题出在路径上。

这是对话框 XML:

<dialog jcr:primaryType="cq:Dialog"
        title="Lead Machine"
        xtype="dialog">
    <items jcr:primaryType="cq:TabPanel">
        <items jcr:primaryType="cq:WidgetCollection">
            <generalTab jcr:primaryType="cq:Panel"
                        title="Geral">
                <items jcr:primaryType="cq:WidgetCollection">
                    <campanhaID jcr:primaryType="nt:unstructured"
                                allowBlank="false"
                                fieldLabel="Campanha ID"
                                name="./jcr:campanhaid"
                                xtype="textfield" />
                    <titulo jcr:primaryType="nt:unstructured"
                            allowBlank="false"
                            fieldLabel="Título"
                            name="./jcr:titulo"
                            xtype="textfield" />
                    <corFundo jcr:primaryType="nt:unstructured"
                              allowBlank="false"
                              fieldLabel="Cor de Fundo"
                              name="./jcr:corfundo"
                              xtype="colormenu" />
                    <corBotao jcr:primaryType="nt:unstructured"
                              allowBlank="false"
                              fieldLabel="Cor do Botão"
                              name="./jcr:corbotao"
                              xtype="colormenu" />
                    <txtBotao jcr:primaryType="nt:unstructured"
                              allowBlank="false"
                              fieldLabel="Texto do Botão"
                              ame="./jcr:txtBotao"
                              xtype="textfield" />
                    <texto jcr:primaryType="nt:unstructured"
                           allowBlank="true"
                           fieldLabel="Texto"
                           name="./jcr:texto"
                           xtype="richtext" />
                    <observacao jcr:primaryType="nt:unstructured"
                                allowBlank="true"
                                fieldLabel="Observação"
                                name="./jcr:observacao"
                                xtype="richtext" />
                    <layoutForm jcr:primaryType="cq:Widget"
                                fieldDescription="LM com formato simples"
                                fieldLabel="Layout Form"
                                inputValue="true"
                                name="./layoutForm"
                                type="checkbox"
                                xtype="selection" />
                    <agendamento jcr:primaryType="cq:Widget"
                                 fieldDescription="LM com agendamento"
                                 fieldLabel="Agendamento"
                                 inputValue="true"
                                 name="./agendamento"
                                 type="checkbox"
                                 xtype="selection" />
                    <ativo jcr:primaryType="cq:Widget"
                           fieldLabel="Ativo"
                           inputValue="true"
                           name="./ativo"
                           type="checkbox"
                           xtype="selection" />
                </items>
            </generalTab>
            <tab1 jcr:primaryType="cq:Panel" title="Image Properties">
                <image1ResType jcr:primaryType="cq:Widget" ignoreData="{Boolean}true" name="./image1/sling:resourceType" value="foundation/components/image" xtype="hidden"/>
                <image2ResType jcr:primaryType="cq:Widget" ignoreData="{Boolean}true" name="./image2/sling:resourceType" value="foundation/components/image" xtype="hidden"/>
            </tab1>
            <tab2 jcr:primaryType="cq:Widget"
                  cropParameter="./imageCrop"
                  fileNameParameter="./fileName"
                  fileReferenceParameter="./fileReference"
                  mapParameter="./imageMap"
                  name="./file"
                  requestSuffix="/img.jpg"
                  rotateParameter="./imageRotate"
                  title="Image 1"
                  xtype="html5smartimage" />
            <tab3 jcr:primaryType="cq:Widget"
                  cropParameter="./mdImageCrop"
                  fileNameParameter="./mdFileName"
                  fileReferenceParameter="./mdFileReference"
                  mapParameter="./mdImageMap"
                  name="./mdFile"
                  requestSuffix="/mdImage.img.jpg"
                  rotateParameter="./mdImageRotate"
                  title="Image 2"
                  xtype="html5smartimage" />
        </items>
    </items>
</dialog>

【问题讨论】:

    标签: adobe aem


    【解决方案1】:
    Node childNode = currentNode.getNode("file");
    if (childNode != null) {
        if (childNode.hasProperty("fileReferenceParameter")) {
            return childNode.getProperty("fileReferenceParameter").getString();
        }
    }
    

    你为什么在tab1中使用隐藏的imageResType

    您也可以使用以下图片对象:

    <% 
         Image image = new Image(resource, "file"); 
    %>    
    
    <img src='<%=image.getSrc()'/>
    

    【讨论】:

    • 好吧,我从另一个有我想要的东西的对话框复制了这个对话框的一部分,两个图像上传。现在我还有另一个问题,第一次将图像上传到显示图像的组件时,当我重新加载页面并在视觉上编辑组件时,图像消失了,这可能是什么?
    • @Terkhos 请从浏览器控制台添加错误日志,或尝试自己调试
    • 您的代码不起作用,我应该得到什么回报?我无法调试,我相信我的用户无权访问它。您的代码在 childNode.getProperty("fileReferenceParameter") 上失败
    • @Terkhos 请提供具体原因。是例外还是其他?
    • @Terkhos fileReferenceParameter 是您在大坝中的图像的路径
    猜你喜欢
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 2019-02-23
    相关资源
    最近更新 更多