Windchil API下載文件的前後臺實現

下載的JSP文件:netmarkets/jsp/ext/tct/partlistsearch/export.jsp

<%@page language="java" session="true" pageEncoding="UTF-8"%>
<%@ page import="wt.httpgw.URLFactory" %>
<%@ page import="ext.tct.globalamlsearch.util.ExportUtil" %>
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ taglib prefix="jcamvc" uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib uri="http://www.ptc.com/windchill/taglib/mvc" prefix="mvc"%>
<%@ taglib prefix="wrap" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="wctags"%>
<%@ include file="/netmarkets/jsp/util/begin.jspf"%>

<title>downloading.....</title>
<div align="center"><img src="netmarkets/jsp/ext/tct/partlistsearch/loading.gif"/>
<BR>
It could take a small amount of time, please waiting!
</div>
<%
URLFactory urlFactory = new URLFactory();
String baseUrl = urlFactory.getBaseURL().toExternalForm();
ExportUtil.downloadFile(response);
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
%>
<script type="text/javascript">

			window.function(){exportExcel();} 
			
			function exportExcel(){							
				var tempUrl = '<%=baseUrl%>netmarkets/jsp/ext/tct/partlistsearch/export.jsp';				
				PTC.util.downloadUrl(tempUrl);	//windchill 自帶的API,直接調用
			}
						
			
</script>


<%@ include file="/netmarkets/jsp/util/end.jspf"%>

功能頁面:

<%@page language="java" session="true" pageEncoding="UTF-8"%>
<%@ taglib prefix="jca"
	uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ taglib prefix="jcamvc"
	uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib uri="http://www.ptc.com/windchill/taglib/mvc" prefix="mvc"%>
<%@ taglib prefix="wrap"
	uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="wctags"%>

<%@ include file="/netmarkets/jsp/util/begin.jspf"%>
<style>
#cover {
	position: fixed;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	background-color: rgba(0, 0, 0, 0.3);
	display: none;
	z-index: 1000;
}
</style>
<%@ include file="/netmarkets/jsp/components/includeWizBean.jspf"%>
<%@page import="java.util.*"%>
<%@ page import="wt.httpgw.URLFactory"%>

<%
URLFactory urlFactory = new URLFactory();
String baseUrl = urlFactory.getBaseURL().toExternalForm();
%>

<table width="100%">
	<tr>
		<td height="25" width="160" class="wizFormLabel" align="left"><font
			size="3" color="red">*Product Name:</font></td>
		<td height="25" width="200" align="left"><input type="text"
			style="width: 100%" size="10px" id="searchContainer" /></td>
		<td align="left" height="25" class="wizFormLabel">
			<div id="searchBtnID"></div>
		</td>
	</tr>
</table>
<div id="cover">這是一個遮罩</div>
<div id="mvcTable">
	<jsp:include
		page="${mvc:getComponentURL('ext.tct.partlistsearch.view.PartListSearchCommonBuilder')}"
		flush="true" />
</div>



<script type="text/javascript">
Ext.onReady(function(){
	var searchBtn = new Ext.Button({
		id : "searchBtn",
		applyTo : 'searchBtnID',
		autoShow : true,
		type : 'button',
		text : 'Search',
		listeners : {
			'click' : function() {
				submitParameters();
			}
		}
	});
	
	var search = new Ext.form.ComboBox({
        store:new Ext.data.JsonStore({
			autoLoad : true,  
			url:'netmarkets/jsp/ext/tct/partlistsearch/commonpartsearch.jsp',  
			baseParams: {worktype: 'searchContainer'},
			root: 'root',             
			fields :  ['productName','productOid']  
		}),
        tpl: '<tpl for="."><div ext:qtip="{productName}" class="x-combo-list-item">{productName}</div></tpl>',
		id: "searchContainerID",
		applyTo: 'searchContainer',
		resizable : true,
		width:150,
		displayField:'productName',  
		valueField :'productOid',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true
    });	
	
}); 
	

	function submitParameters() {
			var productName = document.getElementById("searchContainer").value;
			var params = {
				productName:productName
			};
			if (productName == "") {
				Ext.MessageBox.alert('提示','請選擇需要查詢的產品,非常感謝!',null);
			}
			var cover = document.getElementById('cover');
			cover.style.display = 'block';
			setTimeout(function() {
				cover.style.display = 'none';
			}, 2000);
			PTC.jca.table.Utils.reload('ext.tct.partlistsearch.view.PartListSearchCommonBuilder', params, true);		
	}
	
	function makeExcel() {
		var tempUrl = '<%=baseUrl%>netmarkets/jsp/ext/tct/partlistsearch/export.jsp';	
		PTC.util.downloadUrl(tempUrl);	//下載的核心代碼
	}
</script>

<table width="100%">
	<tr>
		<td align="center" height="25" class="wizFormLabel">
			<button type="button" id="exprotBtnID" class=" x-btn-text"
				onclick="javascript:makeExcel();">Export</button>
		</td>
	</tr>
</table>
<%@ include file="/netmarkets/jsp/util/end.jspf"%>

頁面顯示:
在這裏插入圖片描述

下載的action要註冊一下:
/codebase/config/actions/custom-actions.xml

<objecttype name="commonsearch" class="wt.part.WTPart" resourceBundle="ext.tct.partlistsearch.resource.PartListSearchResource">
    <action name="partlistsearchbynumber">
        <command url="netmarkets/jsp/ext/tct/partlistsearch/partlistsearch4partnumber.jsp" windowType="page"/>
    </action>
    <action name="partlistsearchbybom">
        <command url="netmarkets/jsp/ext/tct/partlistsearch/relationshipbomsearch4partList.jsp" windowType="page"/>
    </action>
    <action name="partlistsearchexport">
        <command url="netmarkets/jsp/ext/tct/partlistsearch/partlistexport4container.jsp" windowType="page"/>
    </action>
    <!--下載的註冊-->
    <action name="export">
        <command url="netmarkets/jsp/ext/tct/partlistsearch/export.jsp" windowType="popup"/>
    </action>
</objecttype>
<!-- Add PartList Search  by wonly.wu 2018-09-26 end -->
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章