Calling A bounded taskflow from another

6.8k views Asked by At

I have a two taskflows, taskflow A with page fragment(.jsff) as view and taskflow B with a page(.jspx). Both of them are bounded. Is it possible to open that page (taskflow B) from any action occurred in the view of taskflow A?

Here is my situation. I have a bounded taskflow album-task-flow.xml. It has two view album-list.jsff and album-details.jsff. It is possible to swap these view. This taskflow has been added to a page within af:region.

The view album-details.xml has images. Beside each image I have a link. On clicking that link I have to display that image in a new tab and have to open the browser's print option dialog.

How can I achieve this functionality?

2

There are 2 answers

0
Tapas Bose On BEST ANSWER

I created 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>

In this page by the region "albumrg" I have added a task-flow album-task-flow. This album-task-flow has two page fragments added as the view:

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

From this code we can see there are two views: album-list and album-details, and a managed bean album has been defined. Also it has two control flow rules. These rules are used to navigate or swap the views album-list and album-details.

Album list contain list of album. This is a model created based on data coming from UCM. This is not the part of the topic I think. Each Album item has a commandLink by which it can takes into the Detail view. The Detail view consists of thumbnails of the images of that particulate album.

I not giving the code of these two page fragment. The only thing is needed is the commandLink resides below each image thumbnail, and on-clicking that link it will open a new tab or window. The page of the newly opened tab will have only the enlarged or original image of that thumbnail. Also when this tab will open at that moment the print dialog of the browser must be opened to print that page. I think I made you able to understand my requirement.

Here is the code for that commandLink and also my solution:

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

The image thumbnails are encapsulated into a data structure of List>.

Now I made another taskflow. This is the taskflow B, that is 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>

From the code we can see this taskflow has a jspx page, i.e., album-detail-print.jspx as its default view and also has a managed bean with name albumPrint.

What I need is to open this taskflow in a new tab. So from the actionListener of the aforesaid commandLink I did this:

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

And this is opening that album-detail-print.jspx in a new tab. The following code is from 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>

In this is the 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;
    }
}
0
lokoko On

The flow mentioned above seems to be pretty right. Handling TFs does consume a lot of lines of code.