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