2012-05-21 2 views
2

Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate Provider를 사용하여 웹 애플리케이션을 수행하고 있습니다. 응용 프로그램은 Tomcat 6.35에서 실행됩니다.Primefaces fileUpload가 작동하지 않고 FileUploadFilter가 두 번 호출됩니다.

친숙한 URL 및 스프링 보안 3.1.0.RELEASE를 위해 PrettyFaces 3.3.2를 사용합니다.

Primefaces 3.1을 사용하고 Primefaces의 fileupload 구성 요소를 사용하려고합니다. 슬프게도 작동하지 않습니다.

나는 내 pom.xml 파일에 좋은 종속성이

<dependency> 
      <groupId>commons-fileupload</groupId> 
      <artifactId>commons-fileupload</artifactId> 
      <version>1.2.1</version> 
     </dependency><dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>1.4</version> 
     </dependency> 

내 web.xml의 :

<h:form enctype="multipart/form-data" id="testFileupload"> 
      <pou:fieldset legend="Upload de fichiers"> 
       <pou:messages showDetail="true"/> 

       <pou:fileUpload id="fileUploadInputTest" fileUploadListener="#{siteFormManager.handleFileUpload}" auto="true" dragDropSupport="false"/> 
      </pou:fieldset> 
     </h:form> 

또는

: 나는 다음을 시도 뷰에서

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse 
    from complaining that 3.0 is not a valid version <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"> --> 
<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" 
    version="2.5"> 

    <!-- Theme pour prime --> 
    <context-param> 
     <param-name>primefaces.THEME</param-name> 
     <param-value>glass-x</param-value> 
    </context-param> 

    <!-- The definition of the Root Spring Container shared by all Servlets 
     and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring/applicationContext.xml 
      /WEB-INF/spring/security-app-context.xml 
     </param-value> 
    </context-param> 

    <context-param> 
     <param-name>javax.faces.DEVELOPMENT</param-name> 
     <param-value>false</param-value> 
    </context-param> 

    <context-param> 
     <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> 
     <param-value>true</param-value> 
    </context-param> 


    <!-- jboss-el --> 
    <context-param> 
     <param-name>com.sun.faces.expressionFactory</param-name> 
     <param-value>org.jboss.el.ExpressionFactoryImpl</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>/tmp/primefacesFileupload</param-value> 
     </init-param> 
    </filter> 

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

<!-- Filter for setting all the requests and responses to UTF-8 encoding--> 
    <filter> 
     <filter-name>spring-encoding-filter</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> 
    </filter> 

    <filter-mapping> 
     <filter-name>spring-encoding-filter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <!-- Localisation --> 
    <filter> 
     <filter-name>localizationFilter</filter-name> 
     <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>localizationFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 


    <!-- Spring security --> 
    <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> 


    <!-- Pretty faces --> 
    <filter> 
     <filter-name>Pretty Filter</filter-name> 
     <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>Pretty Filter</filter-name> 
     <url-pattern>/*</url-pattern> 
     <dispatcher>FORWARD</dispatcher> 
     <dispatcher>REQUEST</dispatcher> 
     <dispatcher>ERROR</dispatcher> 
    </filter-mapping> 


    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- place constraints on a single user's ability to log in to your application --> 
    <listener> 
     <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> 
    </listener> 

    <!-- Processes application requests --> 
    <servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/app/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/spring/</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> 
     <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> 

    <resource-ref> 
     <res-ref-name>jsf/ProjectStage</res-ref-name> 
     <res-type>java.lang.String</res-type> 
     <jndi-name>javax.faces.PROJECT_STAGE</jndi-name> 
    </resource-ref> 

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

<h:form enctype="multipart/form-data"> 
    <pou:messages showDetail="true"/> 

    <pou:fileUpload value="#{siteFormManager.file}" mode="simple"/> 

    <pou:commandButton value="Submit" ajax="false" actionListener="#{siteFormManager.upload}" action="#{siteFormManager.uploadAction}"/> 
</h:form> 
내 콩

@Component 
@Scope(value = "request") 
public class SiteFormManager { 

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

    /** 
    * Le file to upload 
    */ 
    private UploadedFile file; 

    public void handleFileUpload(FileUploadEvent event) { 
     final UploadedFile lfile = event.getFile(); 
     logger.debug("SiteFormManager::handleFileUpload {} --> File equals {}", event, lfile); 
    } 

    public void handleFileUpload() { 
     logger.debug("SiteFormManager::handleFileUpload without params"); 
    } 

    public String uploadAction() { 
     logger.debug("SiteFormManager::uploadAction --> File equals {}", file); 
     return null; 
    } 

    public UploadedFile getFile() { 
     return file; 
    } 

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

문제에서

내 콩의 파일은 항상 null 인 것입니다! Tomcat 7에서 시도했지만 아무 것도 바뀌지 않았습니다. Richfaces의 fileUpload 구성 요소를 사용해 보았습니다.하지만 충돌은 피하기 위해 두 개의 구성 요소 라이브러리가 포함되어 있습니다.

Netbeans 7에서 내 응용 프로그램을 디버깅하고 FileUploadFilter :: doFilter에 중단 점을 삽입했습니다. doFilter가 두 번 호출된다는 것을 알았습니다. MultipartRequest가 처음 만들어지면 양식 입력을 파싱하고 파일을 감지합니다. 하지만 두 번째로 요청이 소비 된 것으로 보이며 MultipartRequest에 아무 것도 채워지지 않습니다. Primefaces FileUploadRenderer는 두 번째 MultipartRequest를 사용하므로 해당 파일에 파일이 없습니다.

FileUploadFilter가 두 번 호출되는 것이 정상입니까? fileUpload 구성 요소는 어떻게 작동합니까?

솔루션은

난 단지 web.xml 파일을 변경 prettyfaces 필터에 ASYNC을 추가하고 파일 업로드 필터의 모든 디스패처를 제거했다. 당신

마지막 web.xml을

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse 
    from complaining that 3.0 is not a valid version <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"> --> 
<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" 
    version="2.5"> 

    <!-- Theme pour prime --> 
    <context-param> 
     <param-name>primefaces.THEME</param-name> 
     <param-value>glass-x</param-value> 
    </context-param> 

    <!-- The definition of the Root Spring Container shared by all Servlets 
     and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring/applicationContext.xml 
      /WEB-INF/spring/security-app-context.xml 
     </param-value> 
    </context-param> 

    <context-param> 
     <param-name>javax.faces.DEVELOPMENT</param-name> 
     <param-value>false</param-value> 
    </context-param> 

    <context-param> 
     <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> 
     <param-value>true</param-value> 
    </context-param> 


    <!-- jboss-el --> 
    <context-param> 
     <param-name>com.sun.faces.expressionFactory</param-name> 
     <param-value>org.jboss.el.ExpressionFactoryImpl</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>/tmp/primefacesFileupload</param-value> 
     </init-param> 
    </filter> 

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

<!-- Filter for setting all the requests and responses to UTF-8 encoding--> 
    <filter> 
     <filter-name>spring-encoding-filter</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> 
    </filter> 

    <filter-mapping> 
     <filter-name>spring-encoding-filter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <filter> 
     <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> 
     <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 


    <!-- Localisation --> 
    <filter> 
     <filter-name>localizationFilter</filter-name> 
     <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>localizationFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 


    <!-- Spring security --> 
    <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> 


    <!-- Pretty faces --> 
    <filter> 
     <filter-name>Pretty Filter</filter-name> 
     <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>Pretty Filter</filter-name> 
     <url-pattern>/*</url-pattern> 
     <dispatcher>FORWARD</dispatcher> 
     <dispatcher>REQUEST</dispatcher> 
     <dispatcher>ERROR</dispatcher> 
     <dispatcher>ASYNC</dispatcher> 
    </filter-mapping> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- place constraints on a single user's ability to log in to your application --> 
    <listener> 
     <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> 
    </listener> 

    <!-- Processes application requests --> 
    <servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/app/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/spring/</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> 
     <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> 

    <resource-ref> 
     <res-ref-name>jsf/ProjectStage</res-ref-name> 
     <res-type>java.lang.String</res-type> 
     <jndi-name>javax.faces.PROJECT_STAGE</jndi-name> 
    </resource-ref> 

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

감사합니다.

답변

2

나는 당신이 당신의 PrettyFaces 필터 매핑에 ASYNC 디스패처를 추가 할 필요가 믿는 :

<!-- Pretty faces --> 
<filter> 
    <filter-name>Pretty Filter</filter-name> 
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>Pretty Filter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
    <dispatcher>ASYNC</dispatcher> 
</filter-mapping> 

PrimeFaces은 내가 잘못 아니에요 경우 구성 요소가 ASYNC 업로드를 사용하여 업로드 할 수 있습니다.

+0

안녕하세요! PrickFaces FileUpload Filter에서 모든 Dispatcher를 제거하고 제거하는 것처럼 PrettyFilter에 ASYNC를 추가했습니다. 감사합니다! –

관련 문제