fileUploadDownload.xhtml
<h:form id="form" enctype="multipart/form-data">
<p:growl id="growl" sticky="true" showsDetail="true" />
<div id="header">
<ui:insert name="header">
<ui:include src="/templates/header.xhtml" />
</ui:insert>
</div>
<p:dialog modal="true" widgetVar="statusDialog" header="Status"
draggable="false" closable="false" resizable="false">
<p:graphicImage value="/resources/images/ajaxloading.gif" />
</p:dialog>
<p:growl id="msgs" showDetail="true" />
<p:tabView>
<p:tab title="Upload File">
</p:tab>
<p:tab title="Download File">
<p:commandButton value="Download" icon="ui-icon-circle-arrow-s"
ajax="false"
actionListener="#{fileDownloadView.download(fileDownloadView.selectedFile)}">
<f:setPropertyActionListener value="#{dfTable}"
target="#{fileDownloadView.selectedFile}" />
</p:commandButton>
<p:dataTable id="downFilesTable" var="dfTable" paginator="true"
rows="15" rowsPerPageTemplate="5,10,15,20,25,30"
sortBy="#{dfTable.bankName}" expandableRowGroups="true"
value="#{copyFilesView.copyFilesModelList}" widgetVar="table"
selection="#{fileDownloadView.selectedFile}"
rowKey="#{dfTable.fileName}">
<f:facet name="header">
Copy Output Files
</f:facet>
<p:column selectionMode="single"
style="width:16px;text-align:center" />
<p:headerRow>
<p:column colspan="5" headerText="Bank Name">
<h:outputText value="#{dfTable.bankName}" />
</p:column>
</p:headerRow>
<p:column headerText="Bank Identifier"
filterBy="#{dfTable.bankIdentifier}" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{dfTable.bankIdentifier}" />
</p:column>
<p:column headerText="Output File Name"
filterBy="#{dfTable.fileName}" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{dfTable.fileName}" />
</p:column>
<p:column headerText="File Type" filterBy="#{dfTable.fileType}"
footerText="equals" filterMatchMode="equals">
<f:facet name="filter">
<p:selectOneButton onchange="PF('table').filter()">
<f:selectItem itemLabel="All" itemValue="" />
<f:selectItem itemLabel="Update" itemValue="Update" />
<f:selectItem itemLabel="Full" itemValue="Full" />
</p:selectOneButton>
</f:facet>
<h:outputText value="#{dfTable.fileType}" />
</p:column>
<p:column headerText="File Timestamp" sortBy="#{dfTable.timestamp}">
<h:outputText value="#{dfTable.timestamp}" />
</p:column>
</p:dataTable>
</p:tab>
</p:tabView>
</h:form>
FileDownloadView.java
public class FileDownloadView
{
private CopyFilesModel selectedFile;
public CopyFilesModel getSelectedFile()
{
return selectedFile;
}
public void setSelectedFile(CopyFilesModel selectedFile)
{
this.selectedFile = selectedFile;
}
public void download(CopyFilesModel selectedFile) throws IOException
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
String filename = selectedFile.getFileName();
// not sure about the rest of the code... I've tried many different ways...
}
}
模型
public class CopyFilesModel implements Serializable
{
private String bankName;
private String bankIdentifier;
private String fileName;
private String fileType;
private String timestamp;
// *******************GETTERS & SETTERS *****************************
public String getBankName()
{
return bankName;
}
public void setBankName(String bankName)
{
this.bankName = bankName;
}
public String getBankIdentifier()
{
return bankIdentifier;
}
public void setBankIdentifier(String bankIdentifier)
{
this.bankIdentifier = bankIdentifier;
}
public String getFileName()
{
return fileName;
}
public void setFileName(String fileName)
{
this.fileName = fileName;
}
public String getFileType()
{
return fileType;
}
public void setFileType(String fileType)
{
this.fileType = fileType;
}
public String getTimestamp()
{
return timestamp;
}
public void setTimestamp(String timestamp)
{
this.timestamp = timestamp;
}
}
信息
我有一个数据表,该数据表是从另一个xhtml页面的后备bean填充的,因为它们对数据表使用相同的信息。在上面的代码中,我想从数据表中选择一行/文件,然后使用commandButton下载文件。我希望用户选择将文件保存到的位置。有人可以通过将数据表中的对象传递到支持bean的下载方法中,然后将文件保存到用户指定的任何位置,来帮助我从目录/ moe / del / hc / arc / 20180905 / send下载文件吗?该文件的类型为File,看起来像HTUZ001D,没有扩展名。