1

The listener doesn't respond to my action:

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

and here is the backing bean:

@ManagedBean
@ViewScoped
public class TestClass {

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

}

and here is my 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>

The problem is that the method uploadImage doesn't get called.

What is wrong with my code or what is missing?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
user1240119
  • 21
  • 1
  • 4
  • is your form got enctype="multipart/form-data" , like this : – Daniel Apr 01 '12 at 12:00
  • i have this exception in log tomcat 01/04/2012 01:00:57 م org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/UploadedImageTest] threw exception java.io.IOException: Processing of multipart/form-data request failed. \tmpDir\upload__5e4873ce_1366d8db020__8000_00000020.tmp (The system cannot find the path specified) – user1240119 Apr 01 '12 at 12:02
  • 1
    yes i have this line in my form – user1240119 Apr 01 '12 at 12:04
  • 1
    it can't find your upload dir... try changing into /tmpDir3 (removed one / ) – Daniel Apr 01 '12 at 12:04
  • nothing ,doesnt effect uploadDirectory /tmpDir – user1240119 Apr 01 '12 at 12:09
  • take a look at this detailed answer.... http://stackoverflow.com/a/8880083/617373 – Daniel Apr 01 '12 at 12:12
  • 1
    Are you looking at the right bean? Your binding says `#{ADD.uploadImage}`, but the bean you've shown will be called `testClass`, NOT `ADD`. – Arjan Tijms Apr 01 '12 at 12:59
  • yes it is my mistake when i post this issue into web – user1240119 Apr 01 '12 at 13:41
  • possible duplicate of [How to use PrimeFaces p:fileUpload? Listener method is never invoked](http://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked) – BalusC Mar 13 '13 at 12:52

1 Answers1

0

If you add the @ManagedBean annotation, the name of the instances of your bean will be the name of your class (with a lower-case first letter). In your example, as the name of your class is TestClass, the name of your bean will be testClass.

So, when you write an EL expression that should invoke a method on this bean, you have to write #{testClass.myMethod} (in your case, this will be #{testClass.uploadImage}.

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

funkygono
  • 426
  • 3
  • 5