Primefaces FileUpload not working in Spring Boot

前端 未结 3 1983
失恋的感觉
失恋的感觉 2021-01-05 18:24

I\'m running my JSF project launching it with Spring Boot and taking advantage of the whole Spring environment. The configuration is: Mojarra 2.2.8 + Primefaces 5.1 + Spring

3条回答
  •  萌比男神i
    2021-01-05 18:35

    Finally, I got it working using the Apache Commons library. Similarly that what we might do in a standard web.xml file, that's my context initializer:

    @Bean
    public ServletContextInitializer initializer() {
        return new ServletContextInitializer() {
            @Override
            public void onStartup(ServletContext servletContext)
                    throws ServletException {
                servletContext.setInitParameter("primefaces.THEME", "bluesky");
                servletContext.setInitParameter(
                        "javax.faces.FACELETS_SKIP_COMMENTS", "true");
                servletContext.setInitParameter(
                        "com.sun.faces.expressionFactory",
                        "com.sun.el.ExpressionFactoryImpl");
                servletContext.setInitParameter("primefaces.UPLOADER",
                        "commons");
            }
        };
    }
    

    I explicitly tell Primefaces to use the commons uploader, like said in docs (the other choice is to use native, which is not working).

    Then, just adding this two dependencies to the project, we're ready to go:

    
        commons-fileupload
        commons-fileupload
        1.3
    
    
        commons-io
        commons-io
        2.2
    
    

    I keep the thread opened for some response based in the native mode.

    See also:

    • How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null

提交回复
热议问题