简体   繁体   中英

p:fileUpload prime faces

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM