AEM Workflow - 在自定义对话框中使用在上一个流程步骤中收集的数据设置值

AEM Workflow - set values in a custom dialog from with data gathered in previous process step

我的总体目标是:启动一个运行 java class 的流程步骤来收集列表,然后在下一个工作流程步骤中,该列表需要显示在自定义对话框中。

这是我目前拥有的:

我现在遇到的问题是:如何从元数据中获取列表以显示在我的自定义对话框中?

我找了很久,好像从来没有人做过

Please note: this answer was tested and developed on AEM 6.3

这是一个简单的花岗岩 UI 小部件,用于显示当前工作流程中的所有 key/value 对 MetaDataMap(包括在之前的工作流程步骤中设置的)

首先,让我们创建工作流对话框:

在应用程序下创建一个组件:/apps/so-wf-test/wf-components/wf-metadata

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" 
    componentGroup=".hidden"
    jcr:primaryType="cq:Component"
    jcr:title="A dummy component needed for the dialog"
    sling:resourceSuperType="foundation/components/parbase"/>

创建对话框:/apps/so-wf-test/wf-components/wf-metadata/cq:dialog

<?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="nt:unstructured"
    jcr:title="Display all workflow metadata"
    sling:resourceType="cq/gui/components/authoring/dialog">
    <content
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/foundation/container">
        <layout
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns"/>
        <items jcr:primaryType="nt:unstructured">
            <columns
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/container">
                <items jcr:primaryType="nt:unstructured">
                    <metadataList
                       jcr:primaryType="nt:unstructured"
                       sling:resourceType="/apps/so-wf-test/wf-granite-widgets/wf-metadata-list"/>
                </items>
            </columns>
        </items>
    </content>
</jcr:root>

note that above dialog includes a custom granite widget to display the metdata list: <metadataList jcr:primaryType="nt:unstructured" sling:resourceType="/apps/so-wf-test/wf-granite-widgets/wf-metadata-list"/>

现在花岗岩小部件JSP

创建 sling 文件夹:/apps/so-wf-test/wf-granite-widgets/wf-metadata-list

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Folder"/>

内部创建 wf-metadata-list.jsp:

This can be done via Use API or sling models with HTL Or via a servlet. I went with JSP for fast solution for the purposes of this answer.

<%@include file="/libs/granite/ui/global.jsp"%><%
%><%@page import="com.adobe.granite.workflow.WorkflowSession,
                  com.adobe.granite.workflow.exec.WorkItem,
                  com.adobe.granite.workflow.exec.WorkflowData,
                  com.adobe.granite.workflow.metadata.MetaDataMap,
                  org.slf4j.Logger,
                  org.slf4j.LoggerFactory"%>
<%
    // get a logger
    Logger logger = LoggerFactory.getLogger(this.getClass());

    // when a workflow dialog is requested, the workitem id is passed as an attribute "item"
    String workitemId = request.getParameter("item");

    // get workflow session
    WorkflowSession wfSession = resourceResolver.adaptTo(WorkflowSession.class);

    // get the current workitem
    WorkItem workitem = wfSession.getWorkItem(workitemId);

    // get workflow data
    WorkflowData workflowData = workitem.getWorkflowData();

    // get metadata map 
    MetaDataMap metaDataMap = workflowData.getMetaDataMap();

%>
    <h1>MetaDataMap Values:</h1>
<ul>
    <% 
       // Iterate over metaDataMap and print all key/val pairs to a list item
       for (Object entry : metaDataMap.keySet())
       {
          Object objVal = metaDataMap.get(entry);
          String val =  objVal == null ? "" : objVal.toString();
          
          %>
        <li><h3><%=entry%>:  <%=val%></h3></li>
          <%
       }
    %>
</ul>

** 现在只需将对话框连接到您的对话框工作流步骤中 ** 使用路径 /apps/so-wf-test/dialogs/wf-dialog/cq:dialog"

工作流到达对话步骤后,您将看到元数据项列表。

示例:

我创建了一个具有简单步骤的工作示例

  • 第 1 步:将 "someKey"="SOME VALUE" 添加到 MetaDataMap
  • 第 2 步:获取 "someKey" 并打印出来
  • 第 3 步:指向上面对话框的对话框步骤

这是对话框的截图:

这是您可以下载并安装的软件包

https://drive.google.com/file/d/0B-_At1NXpw0EOFNaUVdYcGVHNnM/view?usp=sharing&resourcekey=0-a_8b0SoC25dxwTTCHw2vRg