从另一个调用有界任务流

时间:2012-05-16 13:44:27

标签: java jdeveloper oracle-adf adf-task-flow

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

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

view album-details.xml包含图片。在每张图片旁边,我都有一个链接。点击该链接后,我必须在新标签页中显示该图像,并且必须打开浏览器的打印选项对话框。

如何实现此功能?

2 个答案:

答案 0 :(得分:2)

我创建了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”区域组成的页面中,我添加了一个任务流专辑-task-flow。此album-task-flow有两个页面片段作为视图添加:

<?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>

从这段代码我们可以看到有两个视图:album-list和album-details,并且已经定义了一个托管bean专辑。它还有两个控制流规则。这些规则用于导航或交换视图专辑列表和专辑详细信息。

相册列表包含相册列表。这是基于来自UCM的数据创建的模型。这不是我认为的主题的一部分。每个Album项都有一个commandLink,可以通过它来进入Detail视图。详细信息视图包含该微粒专辑图像的缩略图。

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

以下是该commandLink的代码以及我的解决方案:

<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&gt;的数据结构中。

现在我又做了另一个任务流程。这是任务流B,即album-printtask-flow。

<?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。

我需要的是在新标签中打开此任务流程。所以从上述commandLink的actionListener我做到了这一点:

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());  
}

这是在新标签中打开album-detail-print.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;
    }
}

答案 1 :(得分:1)

上面提到的流程看起来非常正确。处理TF会消耗大量代码。

相关问题