p:fileUpload event not fired on 2.2.1

UI Components for JSF
Post Reply
reseba
Posts: 4
Joined: 04 Aug 2010, 16:03

03 Mar 2011, 15:37

Hello, I'm using primefaces 2.2.1 with spring webflow 2.3.0 and JSF 2.
I tried to upload a file, but the listener seems not to be working.

my page

Code: Select all

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    template="/WEB-INF/layouts/template.xhtml">


<ui:define name="content">

<h:form id="formulario">
  <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
    allowTypes="*.jpg;*.png;*.gif;" description="Images"/>  
</h:form>

</ui:define>
</ui:composition>
my controller

Code: Select all

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.FileUploadEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@ManagedBean
@RequestScoped
public class FileUploadController {

	private Logger logger = LoggerFactory.getLogger(FileUploadController.class);

	public void handleFileUpload(FileUploadEvent event) {
            System.out.println("--------------------ARCHIVO---------"+event.getFile().getFileName());
		logger.info("Uploaded: {}", event.getFile().getFileName());
		FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

}
my web.xml

Code: Select all

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>


   <filter>
        <filter-name>charEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>charEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</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>


    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

<context-param>
  		<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
  		<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
  	</context-param>


    <servlet>
        <servlet-name>Resources Servlet</servlet-name>
        <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>Resources Servlet</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>



    <display-name>a4jEchoText</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                /WEB-INF/config/web-application-config.xml
        </param-value>
    </context-param>


    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>


    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>


    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>-1</param-value>
    </context-param>



    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/tecno/*</url-pattern>
    </servlet-mapping>



    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

   <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>bluesky</param-value>
    </context-param>


</web-app>

rubi
Posts: 160
Joined: 24 May 2010, 16:53

03 Mar 2011, 15:49

I think u need to configure a filter in web.xml like this

Code: Select all

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>
            org.primefaces.webapp.filter.FileUploadFilter
        </filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
Glassfish V3.1.1,Mojarra 2.1.2, PrimeFaces-3.0RC1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests