从另一个任务流调用有界任务流



我有两个任务流,任务流A与页面片段(.jsff(作为视图,任务流B与页面(.jspx(。它们都是有界的。是否可以从任务流 A 视图中发生的任何操作中打开该页面(任务流 B(?

这是我的情况。我有一个有界的任务流专辑任务流.xml。它有两个视图 album-list.jsff 和 album-details.jsff。可以交换这些视图。此任务流已添加到 af:region 中的页面。

查看相册详细信息.xml包含图像。在每个图像旁边,我都有一个链接。单击该链接后,我必须在新选项卡中显示该图像,并且必须打开浏览器的打印选项对话框。

如何实现此功能?

我创建了album.jspx:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
          xmlns:cust="http://xmlns.oracle.com/adf/faces/customizable"
          xmlns:pe="http://xmlns.oracle.com/adf/pageeditor">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document id="d1" title="#{applicationScope.navigationContext.currentNavigationModel.currentSelection.title}">
            <af:form id="f1" usesUpload="true">
                <af:pageTemplate viewId="/oracle/webcenter/portalapp/pagetemplates/WF_Template.jspx"
                         value="#{bindings.pageTemplateBinding}" id="pt1">
                    <f:facet name="content">
                        <pe:pageCustomizable id="pageCustomizable1" inlineStyle="width:968px;">
                            <f:facet name="editor">
                                <pe:pageEditorPanel id="pep1"/>
                            </f:facet>
                            <af:panelGroupLayout layout="vertical" id="pgl1"> 
                                ---
                                <af:region value="#{bindings.albumtaskflow1.regionModel}" id="albumrg"/>
                                ---
                            </af:panelGroupLayout>
                        </pe:pageCustomizable>
                    </f:facet>
                </af:pageTemplate>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

在这个页面中,通过区域"albumrg",我添加了一个任务流专辑任务流。此相册任务流添加了两个页面片段作为视图:

<?xml version="1.0" encoding="UTF-8" ?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
  <task-flow-definition id="album-task-flow">
    <default-activity id="__1">album-list</default-activity>
    <managed-bean id="__15">
      <managed-bean-name id="__13">album</managed-bean-name>
      <managed-bean-class id="__14">com.mhis.webfactory.taskflow.album.AlbumManagedBean</managed-bean-class>
      <managed-bean-scope id="__12">pageFlow</managed-bean-scope>
    </managed-bean>
    <view id="album-list">
      <page>/oracle/webcenter/portalapp/pagefragments/taskflow/album/album-list.jsff</page>
    </view>
    <view id="album-details">
      <page>/oracle/webcenter/portalapp/pagefragments/taskflow/album/album-details.jsff</page>
    </view>
    <control-flow-rule id="__2">
      <from-activity-id id="__3">album-list</from-activity-id>
      <control-flow-case id="__4">
        <from-outcome id="__6">goToDetail</from-outcome>
        <to-activity-id id="__5">album-details</to-activity-id>
      </control-flow-case>
    </control-flow-rule>
    <control-flow-rule id="__7">
      <from-activity-id id="__8">album-details</from-activity-id>
      <control-flow-case id="__10">
        <from-outcome id="__11">goToList</from-outcome>
        <to-activity-id id="__9">album-list</to-activity-id>
      </control-flow-case>
    </control-flow-rule>
    <use-page-fragments/>
  </task-flow-definition>
</adfc-config>

从这段代码中,我们可以看到有两个视图:专辑列表和专辑详细信息,并且已经定义了托管的 Bean 专辑。此外,它还有两个控制流规则。这些规则用于导航或交换视图相册列表和影集详细信息。

相册列表

包含相册列表。这是基于来自UCM的数据创建的模型。我认为这不是主题的一部分。每个"影集"项都有一个命令链接,通过该命令链接可以进入"详细信息"视图。"详细信息"视图由该颗粒相册的图像缩略图组成。

我没有给出这两个页面片段的代码。唯一需要的是命令链接位于每个图像缩略图下方,单击该链接将打开一个新选项卡或窗口。新打开的选项卡的页面将仅包含该缩略图的放大或原始图像。此外,当此选项卡此时打开时,必须打开浏览器的打印对话框才能打印该页面。我想我让你能够理解我的要求。

这是该命令链接的代码,也是我的解决方案:

<af:iterator value="#{pageFlowScope.album.albumDetailCurrent}" id="i4" var="images" varStatus="parentStatus"
             rows="#{pageFlowScope.album.numberOfAlbumDetailRow}">
    <af:iterator value="#{images}" var="image" id="i5" varStatus="childStatus">
        <af:commandLink styleClass="btnPrint" id="cl10" actionListener="#{pageFlowScope.album.printImage}">
             <f:attribute name="parentStatus" value="#{parentStatus.index}"/>
             <f:attribute name="childStatus" value="#{childStatus.index}"/>
         </af:commandLink>
    </af:iterator>
</af:iterator>

图像缩略图封装在 List> 的数据结构中。

现在我做了另一个任务流。这是任务流 B,即专辑-打印任务-流。

<?xml version="1.0" encoding="UTF-8" ?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
  <task-flow-definition id="album-printtask-flow">
    <default-activity id="__1">album-detail-print</default-activity>
    <managed-bean id="__4">
      <managed-bean-name id="__3">albumPrint</managed-bean-name>
      <managed-bean-class id="__6">com.mhis.webfactory.taskflow.album.AlbumPrintManagedBean</managed-bean-class>
      <managed-bean-scope id="__5">pageFlow</managed-bean-scope>
    </managed-bean>
    <view id="album-detail-print">
      <page id="__2">/oracle/webcenter/portalapp/pages/album-detail-print.jspx</page>
    </view>
  </task-flow-definition>
</adfc-config>

从代码中我们可以看到这个任务流有一个jspx页面,即album-detail-print.jspx作为其默认视图,并且还有一个名为albumPrint的托管bean。

我需要的是在新选项卡中打开此任务流。因此,从上述命令链接的动作侦听器中,我这样做了:

public void printImage(ActionEvent event) {
        String taskflowDocument = "/WEB-INF/album-printtask-flow.xml";
        String taskflowId = "album-printtask-flow";        
        Integer parentStatus = (Integer)event.getComponent().getAttributes().get("parentStatus");
        Integer childStatus = (Integer)event.getComponent().getAttributes().get("childStatus");        
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("image", getAlbumDetailCurrent().get(parentStatus).get(childStatus));        
        Map<String, Object> params = new HashMap<String, Object>();        
        String taskflowURL = ControllerContext.getInstance().getTaskFlowURL(false,new TaskFlowId(taskflowDocument,taskflowId),params);
        FacesContext context = FacesContext.getCurrentInstance();
        ExtendedRenderKitService service = Service.getRenderKitService(context, ExtendedRenderKitService.class);
        StringBuilder script = new StringBuilder();
        script.append("window.open(""+taskflowURL+"");");
        service.addScript(FacesContext.getCurrentInstance(), script.toString());  
}

这是在新选项卡中打开该专辑详细信息打印.jspx。以下代码来自 album-detail-print.jspx:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document id="d1" title="Print">
            <af:resource type="javascript" source="/js/js/jquery-1.7.1.min.js"/>
            <af:form id="f1">
                <af:image source="http://#{facesContext.externalContext.request.serverName}/file/#{pageFlowScope.albumPrint.image.docName}&amp;Rendition=Web" id="i3" shortDesc="#{pageFlowScope.albumPrint.image.title}"/>
            </af:form>            
            <af:resource type="javascript">
                $(document).ready(function () {                    
                    window.print();
                });
            </af:resource>            
        </af:document>
    </f:view>
</jsp:root>

这是AlbumPrintManagedBean:

package com.mhis.webfactory.taskflow.album;
import com.mhis.portal.backing.main.JSFUtils;
import com.mhis.webfactory.taskflow.album.model.Image;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
public class AlbumPrintManagedBean {
    private Image image;
    public AlbumPrintManagedBean() {
        super();
        image = (Image)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("image");
    }
    private String jym="JYM";
    public void setImage(Image image) {
        this.image = image;
    }
    public Image getImage() {
        return image;
    }
}

上面提到的流程似乎非常正确。处理 TF 确实会消耗大量代码行。