我创建了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>
从这段代码中我们可以看到有两个视图:album-list 和album-details,并且已经定义了一个托管bean 相册。它还有两个控制流规则。这些规则用于导航或交换视图专辑列表和专辑详细信息。
专辑列表包含专辑列表。这是基于来自 UCM 的数据创建的模型。这不是我认为的主题的一部分。每个专辑项目都有一个 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>的数据结构。
现在我做了另一个任务流。这是任务流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());
}
这是在新选项卡中打开专辑详细信息打印.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}&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;
}
}