下面是一个简单的granite UI小部件,用于显示当前工作流中的所有键/值对
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>
注意,上面的对话框包括一个自定义granite小部件,用于显示metdata列表:
<metadataList jcr:primaryType="nt:unstructured" sling:resourceType="/apps/so-wf-test/wf-granite-widgets/wf-metadata-list"/>
现在是granite小部件JSP
创建吊索文件夹:
/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
:
这可以通过将API或sling模型与HTL一起使用或通过servlet来实现。为了回答这个问题,我使用了JSP作为快速解决方案。
<%@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"
到元数据映射
-
第2步:获取
"someKey"
-
步骤3:对话框步骤指向上面的对话框
这是一个你可以下载并安装的软件包
https://drive.google.com/file/d/0B-_At1NXpw0EOFNaUVdYcGVHNnM/view?usp=sharing&resourcekey=0-a_8b0SoC25dxwTTCHw2vRg