2012-04-01 43 views
1

聽者不以我的行動作出迴應:號碼:文件上傳總理面臨

<h:form> 
    <p:fileUpload mode="simple" fileUploadListener="#{ADD.uploadImage}" auto="true"/> 
</h:form> 

,這裏是支持bean:

@ManagedBean 
@ViewScoped 
public class TestClass { 

    public void uploadImage(FileUploadEvent e){ 
     System.out.println("EVENT"); 
    } 

} 

這裏是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 

    <filter> 
     <filter-name>PrimeFaces FileUpload Filter</filter-name> 
     <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> 
     <init-param> 
      <param-name>thresholdSize</param-name> 
      <param-value>51200</param-value> 
     </init-param> 
     <init-param> 
      <param-name>uploadDirectory</param-name> 
      <param-value>/tmpDir3/</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>PrimeFaces FileUpload Filter</filter-name> 
     <servlet-name>Faces Servlet</servlet-name> 
    </filter-mapping> 

    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>/faces/*</url-pattern> 
    </servlet-mapping> 

    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 

    <welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
</web-app> 

問題是方法uploadImage沒有被調用。

我的代碼有什麼問題或缺少什麼?

+0

是您的形式得到enctype =「multipart/form-data」,像這樣: Daniel 2012-04-01 12:00:18

+0

我有這個異常在日誌tomcat 01/04/2012 01:00:57مorg。 apache.catalina.core.StandardWrapperValve調用 SEVERE:servlet [Faces Servlet]與path [/ UploadedImageTest]上下文中的Servlet.service()引發異常 java.io.IOException:處理multipart/form-data請求失敗。 \ tmpDir \ upload__5e4873ce_1366d8db020__8000_00000020.tmp(系統找不到指定的路徑) – user1240119 2012-04-01 12:02:46

+1

是的,我在我的表單中有這條線 – user1240119 2012-04-01 12:04:01

回答

0

如果添加@ManagedBean註釋,bean實例的名稱將是您的類的名稱(帶小寫的第一個字母)。在你的例子中,因爲你班的名字是TestClass,你的bean的名字是testClass

所以,當你寫一個EL表達式應該調用方法對這個bean,你必須寫#{testClass.myMethod}(在你的情況,這將是#{testClass.uploadImage}

參見:http://docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedBean.html