0
votes

Now I am using Primefacs 3.3.1 and JSF 2.0 for my application. Now I am facing a problem that primefaces FileUploadEvent listener does not work even form submit. There is no erorr and exception in my log file. But, it does not work. What I am missing, lib or configuration? BTW, I use JBoss 7.1.1 application server.

Lib

primefaces-3.3.1.jar
commons-io-1.4.jar
commons-fileupload-1.2.1.jar
poi-3.7.jar

mypages.xhtml

<h:form enctype="multipart/form-data">            
    <p:fileUpload fileUploadListener="#{FileUploadController.handleFileUpload}"  
            mode="advanced"  
            update="messages"   
            multiple="true"  
            sizeLimit="100000"   
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>  
    <p:commandButton value="Submit" ajax="false" actionListener="#{FileUploadController.upload}"/>  
    <!-- or -->
    <p:commandButton value="Submit" ajax="false" action="#{FileUploadController.upload}"/>  
</h:form>   

FileUploadController.java

@Scope(ScopeType.CONVERSATION)
@Name("FileUploadController")
public class FileUploadController {
    private List<UploadedFile> uploadedFileList = new ArrayList<UploadedFile>();

    public void handleFileUpload(FileUploadEvent event) {
        System.out.println("handleFileUpload()....");
        UploadedFile file = event.getFile();
        uploadedFileList.add(file);
        FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  

    public void upload() {
        System.out.println("Number of Uploaded Files : " + uploadedFileList.size());
    }
}

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_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <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>Faces Servlet</url-pattern>
    </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>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>#{GuestPreferences.theme}</param-value>
    </context-param>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
    </listener>
    <filter>
        <filter-name>Seam Multipart Filter</filter-name>
        <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Seam Multipart Filter</filter-name>
        <url-pattern>*.seam</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>Seam Filter</filter-name>
        <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <url-pattern>/seam/resource/*</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-beans.xml</param-value>
    </context-param>
    <security-constraint>
        <display-name>Restrict raw XHTML Documents</display-name>
        <web-resource-collection>
            <web-resource-name>XHTML</web-resource-name>
            <url-pattern>*.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint />
    </security-constraint>
</web-app>
1
Remove Seam and retry.BalusC
@BalusC, if I remove Seam, can I still use Seam in my application?Zaw Than oo
Just to exclude one and other :) You've there a Seam multipart filter which suggests that it's also parsing the HTTP request as multipart/form-data. But a HTTP request can be parsed only once.BalusC
@BalusC, even I remove Seam Multipart Filter, it does not invoke listener metod. BTW, What can I need to do for upload with ajax request? Could you provide whatever solution? Thanks for your time and providing.Zaw Than oo
Well, start debugging the HTTP traffic and HTTP request body parsing.BalusC

1 Answers

0
votes

you should disable seam multipart filter. You should write

web:multipart-filter disabled="true"/> in components.xml . works fine for me.