开发者

PrimeFaces fileUpload event doesn't fire

开发者 https://www.devze.com 2023-04-04 07:05 出处:网络
In my application running on Apache Tomcat 6 I use fileUpload from PrimeFaces 3.0.M3. But it don\'t works correctly. When I upload files its appears in upload directory, but event not fired. Can someb

In my application running on Apache Tomcat 6 I use fileUpload from PrimeFaces 3.0.M3. But it don't works correctly. When I upload files its appears in upload directory, but event not fired. Can somebody help me?

My view code:

<h:form prependId="false" id="uploadForm" enctype="multipart/form-data">
    <p:fileUpload id="uploadControl" fileUploadListener="#{fileUploadBean.uploadHandler}" mode="advanced" />
</h:form>

FileUploadBean class source:

@ManagedBean
@RequestScoped
public class FileUploadBean implements Serializable {

    private static final Logger logger = Logger.getLogger(FileUploadBean.class);

    private UploadedFile file;

    public void uploadHandler(FileUploadEvent event) throws AbortProcessingException {
        logger.debug("uploadHandler(FileUploadEvent event)");
        logger.debug("Uploaded file: " + event.getFile().getFileName());
    }

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }
}

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>casablanca</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>uploadDirectory</param-name>
            <param-value>/tmp</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-na开发者_JAVA百科me>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Resource Servlet</servlet-name>
        <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Resource Servlet</servlet-name>
        <url-pattern>/primefaces_resource/*</url-pattern>
    </servlet-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>*.jsf</url-pattern>
    </servlet-mapping>
    <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>index.jsf</welcome-file>
    </welcome-file-list>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>

    <servlet>
        <servlet-name>StartupServlet</servlet-name>
        <servlet-class>com.greytower.servlets.StartupServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <listener>
        <listener-class>com.project.servlets.ContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>com.project.servlets.LoginServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>AjaxServlet</servlet-name>
        <servlet-class>com.project.servlets.AjaxServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>AjaxServlet</servlet-name>
        <url-pattern>/ajax</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>DownloadServlet</servlet-name>
        <servlet-class>com.project.servlets.DownloadServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>DownloadServlet</servlet-name>
        <url-pattern>/get</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>ImageServlet</servlet-name>
        <servlet-class>com.project.servlets.ImageServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ImageServlet</servlet-name>
        <url-pattern>/image</url-pattern>
    </servlet-mapping>
</web-app>


I think your problem is in your web.xml configuration, you have two different filter mappings declared for the File Upload filter, one of them is incorrect:

<filter-mapping>
   <filter-name>PrimeFaces FileUpload Filter</filter-name>
   <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
   <filter-name>PrimeFaces FileUpload Filter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

Instead you need just this:

 <filter-mapping>
   <filter-name>PrimeFaces FileUpload Filter</filter-name>
   <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

You only want to map the file upload filter to the Faces Servlet.

0

精彩评论

暂无评论...
验证码 换一张
取 消