Primefaces FileUploadEvent侦听器方法不起作用

时间:2013-02-22 08:47:13

标签: java jsf file-upload primefaces

现在我正在使用Primefacs 3.3.1JSF 2.0作为我的申请。现在我面临一个问题,即表面FileUploadEvent监听器即使表单提交也不起作用。 我的日志文件中没有erorr和exception。但是,它不起作用。我缺少什么,lib或配置?顺便说一句,我使用JBoss 7.1.1应用程序服务器。

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 个答案:

答案 0 :(得分:0)

你应该禁用缝多部分过滤器。你应该写

web:multipart-filter disabled =“true”/&gt;在components.xml中。对我来说很好。