我正在使用fileuplod primefaces。我有3個按鈕。每個按鈕都負責上傳文件。我的第一個陡峭的是在我的bean上使用3種方法來上傳每個文件。 有沒有辦法爲所有類型製作相同的方法?每個文件都有他自己的目錄。使用參數製作handleFileupload以共享方法
<h:form enctype="multipart/form-data" style="height:125px;width:75px;">
<p:fileUpload auto="true"
fileUploadListener="#{composantbean.handleFileUpload(???,1)}"
sizeLimit="2097152"
label="Choose"
allowTypes="/(\.|\/)(pdf)$/"
description="Images"/>
</h:form>
在我管理的bean,我想這個解決方案:
public void handleFileUpload(FileUploadEvent event,int i) {
String lienPDN =destination+"PDN\\"+FilenameUtils.getName(event.getFile().getFileName());
File result = new File(lienPDN);
try {
FileOutputStream fileOutputStream = new FileOutputStream(result);
byte[] buffer = new byte[BUFFER_SIZE];
int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}
fileOutputStream.close();
inputStream.close();
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName()+ " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
selcetitem.setLienPdn(lienPDN);
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR,"The files were not uploaded!", "");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
,問題是......? – Aquillo 2013-05-03 08:35:42
hhhhh ..你是對的..我的問題是fileUploadListener =「#{composantbean.handleFileUpload(???,1)}」?????我在這裏寫的 – FERESSS 2013-05-03 08:45:13