2017-07-31 88 views
0

環境中的文件無效:高級文件上傳得與Primefaces

  • Primefaces 6.1
  • 的JavaEE 7
  • Wildfly 10
  • JSF 2.2

當我點擊在選擇後的按鈕該文件,文件var是空的。

Test.xhtml

<!DOCTYPE html> 
<html lang="en" 
     xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html" 
     xmlns:f="http://xmlns.jcp.org/jsf/core" 
     xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui"> 
    <f:view contentType="text/html"> 
     <h:head> 
      <title>Application</title> 
     </h:head> 

     <h:body> 

      <h:form id="frmTest" enctype="multipart/form-data"> 
       <ui:include src="template/messages.xhtml" /> 
       <p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false" 
     update="messages" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" /> 
      </h:form> 
     </h:body> 
    </f:view> 
</html> 

TestBean.java

@ViewScoped 
@ManagedBean 
public class TestBean implements Serializable { 
... 
public void handleFileUpload(FileUploadEvent event) { 
     UploadedFile file = event.getFile();//file is null 
     FacesUtils.addInfoMessage("Succesful" + file.getFileName() + " is uploaded."); 
     System.out.println("Succesful" + event.getFile().getFileName() + " is uploaded."); 
} 
... 
+0

你已經看過了'',如https://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload -listener-method-never-invoked-or-uploaded? –

+0

是的,我已經在stackoverflow中遇到了這個問題,但沒有任何工作。事件甚至沒有被調用。 – Joe

回答

-1

,應該刪除或填寫從fileUpload組件update=""屬性。它在上傳後將文件「重定向」到一個組件。

+0

我測試了它,它也沒有工作。 – Joe