2

I have an application. It's a simple application and one of the features is a file upload (only txt). So I used the file upload component of PrimeFaces, but it doesn't work. I have tried many things, but I can't solve this problem. I am running the application on WildFly 8.0 and I use Spring with JPA.

The dependencies (pom.xml)

There are more dependencies declared, but I think only these are used by PrimeFaces. If you need to view my entire pom.xml, let me know.

<dependency>
    <groupId>org.primefaces.themes</groupId>
    <artifactId>all-themes</artifactId>
    <version>1.0.10</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>4.0</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.1</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.omnifaces</groupId>
    <artifactId>omnifaces</artifactId>
    <version>1.7</version>
    <scope>compile</scope>
</dependency>

web.xml

Again, only the part relevant for primefaces.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns=" http://xmlns.jcp.org/xml/ns/javaee/"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/  http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <display-name>My App</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/spring-context*.xml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

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

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

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

    <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>

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

    <security-constraint>
        <display-name>Protect XHTML Files from direct access
        </display-name>
        <web-resource-collection>
            <web-resource-name>XHTML</web-resource-name>
            <url-pattern>*.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint />
    </security-constraint>

    <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>

    <session-config>
        <session-timeout>960</session-timeout>
    </session-config>

    <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>*.jspa</url-pattern>
    </servlet-mapping>

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/app/errors/viewExpired.jspa</location>
    </error-page>

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/app/errors/error.jspa</location>
    </error-page>

    <error-page>
        <error-code>404</error-code>
        <location>/app/errors/notfound.jspa</location>
    </error-page>

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

faces-config.xml (spring and omnifaces related).

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>

<faces-config-extension>
    <facelets-processing>
        <file-extension>.xhtml</file-extension>
        <process-as>xhtml</process-as>
    </facelets-processing>
</faces-config-extension>

XHTML File.

This is the file where I try to make the upload.

<h:form id="uplFileForm" enctype="multipart/form-data">
    <p:fileUpload id="uplFile"
                  fileUploadListener="#{myManagedBean.save}"
                  mode="advanced"
                  auto="true"
                  label="Select the file"
                  uploadLabel="Upload"
                  cancelLabel="Cancel"
                  invalidSizeMessage="File is too big"
                  invalidFileMessage="Format not supported"
                  dragDropSupport="false"
                  sizeLimit="614572800"
                  allowTypes="/(\.|\/)(txt|TXT)$/" />
</h:form>

My Managed Bean

Well, here I have the method who receives the file and save it, however when I debug the application, the method save(FileUploadEvent) is never called. I think the problem is not here, because, like I said, the method save(FileUploadEvent) is not called.

@ManagedBean
@ViewScoped
public class MyManagedBean extends AbstractMB implements Serializable {
    public void save(FileUploadEvent event) {
        try {
            String fileName = event.getFile().getFileName();

            MyFileUpload myFile = new MyFileUpload();
            byte[] content = event.getFile().getContents();

            myFile.setFilename(event.getFile().getFileName());
            myFile.setContent(conteudo);
            myFile.setChecksum(getHelperService().getCheckSum(content));
            save(myFile);
        }
        catch (ServiceException ex) {
            logger.error("Error, ex);
         }
    }
}

The exception

ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /myapp/app/admin/fileuploads/index.jspa: java.lang.NullPointerException
    at org.omnifaces.config.WebXml.findErrorPageLocation(WebXml.java:176) [omnifaces-1.7.jar:1.7]
    at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.findErrorPageLocation(FullAjaxExceptionHandler.java:270) [omnifaces-1.7.jar:1.7]
    at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handleAjaxException(FullAjaxExceptionHandler.java:200) [omnifaces-1.7.jar:1.7]
    at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handle(FullAjaxExceptionHandler.java:175) [omnifaces-1.7.jar:1.7]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.2.5-jbossorg-3.jar:]
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121) [jsf-impl-2.2.5-jbossorg-3.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.5-jbossorg-3.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.5.jar:2.2.5]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70) [primefaces-4.0.jar:4.0]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
...

Wildfly 8.0.Final startup

09:51:38,482 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
09:51:38,800 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final
09:51:38,884 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting
09:51:39,951 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
09:51:39,969 INFO  [org.xnio] (MSC service thread 1-9) XNIO version 3.2.0.Final
09:51:39,977 INFO  [org.xnio.nio] (MSC service thread 1-9) XNIO NIO Implementation Version 3.2.0.Final
09:51:40,004 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
09:51:40,010 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
09:51:40,021 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
09:51:40,033 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
09:51:40,039 INFO  [org.jboss.as.security] (MSC service thread 1-7) JBAS013170: Current PicketBox version=4.0.20.Final
09:51:40,040 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]
09:51:40,062 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting
09:51:40,063 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-13) JBAS017502: Undertow 1.0.0.Final starting
09:51:40,072 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final)
09:51:40,103 INFO  [org.jboss.as.naming] (MSC service thread 1-14) JBAS011802: Starting Naming Service
09:51:40,103 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-8) JBAS015400: Bound mail session [java:jboss/mail/Default]
09:51:40,127 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
09:51:40,131 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-16) JBAS010417: Started Driver service with driver-name = h2
09:51:40,162 INFO  [org.jboss.remoting] (MSC service thread 1-9) JBoss Remoting version 4.0.0.Final
09:51:40,203 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\Desenvolvimento\Servidores\wildfly-8.0.0.Final/welcome-content
09:51:40,211 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017525: Started server default-server.
09:51:40,242 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017531: Host default-host starting
09:51:40,285 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-11) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
09:51:40,446 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-10) JBAS015012: Started FileSystemDeploymentService for directory C:\Desenvolvimento\Servidores\wildfly-8.0.0.Final\standalone\deployments
09:51:40,448 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "ojdbc6.jar" (runtime-name: "ojdbc6.jar")
09:51:40,448 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-12) JBAS015876: Starting deployment of "myApplication.war" (runtime-name: "myApplication.war")
09:51:40,461 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-13) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
09:51:40,725 INFO  [org.jboss.ws.common.management] (MSC service thread 1-11) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
09:51:41,038 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-16) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 11.2)
09:51:41,049 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-13) JBAS010417: Started Driver service with driver-name = ojdbc6.jar
09:51:44,147 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011401: Read persistence.xml for myApplicationPU
09:51:44,574 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:/datasource/myApplicationds]
09:51:44,576 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'myApplication.war#myApplicationPU'
09:51:44,584 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 52) HHH000204: Processing PersistenceUnitInfo [
    name: myApplicationPU
    ...]
09:51:44,644 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 52) HHH000412: Hibernate Core {4.3.1.Final}
09:51:44,646 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000206: hibernate.properties not found
09:51:44,647 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000021: Bytecode provider name : javassist
09:51:45,108 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016002: Processing weld deployment myApplication.war
09:51:45,164 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-2) HV000001: Hibernate Validator 5.0.3.Final
09:51:45,459 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016005: Starting Services for CDI deployment: myApplication.war
09:51:45,488 INFO  [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.1.2 (Final)
09:51:45,514 INFO  [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016008: Starting weld service for deployment myApplication.war
09:51:45,642 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'myApplication.war#myApplicationPU'
09:51:45,715 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 52) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
09:51:46,027 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 52) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
09:51:46,208 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 52) HHH000397: Using ASTQueryTranslatorFactory
09:51:46,983 WARN  [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
09:51:49,592 INFO  [stdout] (MSC service thread 1-1) 09:51:49,592  INFO config:200 - Inicializando Mojarra 2.2.5-jbossorg-3 20140128-1641 para o contexto '/myApplication'

09:51:53,725 INFO  [stdout] (MSC service thread 1-1) 09:51:53,724  INFO config:1057 - Monitoring file:/C:/Desenvolvimento/Servidores/wildfly-8.0.0.Final/standalone/tmp/vfs/temp/tempfa5b46b5f1a836c/myApplication.war-d0b76188ed68b8f4/WEB-INF/faces-config.xml for modifications

09:51:53,782 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017534: Registered web context: /myApplication
09:51:53,831 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "ojdbc6.jar" (runtime-name : "ojdbc6.jar")
09:51:53,832 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "myApplication.war" (runtime-name : "myApplication.war")
09:51:53,908 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9991/management
09:51:53,909 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9991
09:51:53,909 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final "WildFly" started in 15744ms - Started 442 of 501 services (98 services are lazy, passive or on-demand)

Screenshot

The progress bar doesn't move.

Tiny
  • 27,221
  • 105
  • 339
  • 599
humungs
  • 1,144
  • 4
  • 25
  • 44
  • Your form is missing `enctype="multipart/form-data"` for more info.. http://stackoverflow.com/questions/9170834/how-to-get-jsf-to-upload-file-with-apache-commons-fileupload – Hatem Alimam Apr 03 '14 at 12:18
  • I have added, but same error. – humungs Apr 03 '14 at 12:20
  • Post your full web.xml – Hatem Alimam Apr 03 '14 at 12:22
  • 1
    Make sure ajax is off, because the file upload control needs to post the form for it to work – j.con Apr 03 '14 at 12:30
  • @j.con this is an andvanced mode, so it has to be ajax ! besides it's auto="true"! – Hatem Alimam Apr 03 '14 at 12:51
  • I edited my question with full web.xml @HatemAlimam. – humungs Apr 03 '14 at 12:52
  • The ajax is off @j.con. I tried with `mode="simple"`, but no success. – humungs Apr 03 '14 at 12:53
  • If I use the "simple mode", I need one more command button to start the upload process, right? – humungs Apr 03 '14 at 12:56
  • which version exactly of wildfly ? becuase of you have 8.0.0.Beta1, there's a bug https://issues.jboss.org/browse/WFLY-2329, my best guess it's some sort of a bug in the wildfly.. it's not that stable for me yet... – Hatem Alimam Apr 03 '14 at 12:56
  • I could never get Primefaces' file upload to work, I ended up using h:inputFile http://jsflive.wordpress.com/2013/04/23/jsf22-file-upload/ – j.con Apr 03 '14 at 12:57
  • Also some others having this problem with wildfly http://stackoverflow.com/questions/19402119/file-upload-doesnt-work-with-primefaces-4-0-jsf-mojarra-2-2-3-and-wildfly-beta – Hatem Alimam Apr 03 '14 at 12:58
  • I am using Wildfly 8.0.0.Final. I just try the upload with `mode="advanced` and `auto="false"`. Same error. I am already considering to change my upload strategie. – humungs Apr 03 '14 at 13:00
  • @HatemAlimam, I think it's a servlet 3.1 problem. I will look into it. – humungs Apr 03 '14 at 13:01
  • In other words, you didn't notice any exceptions during server's startup? – BalusC Apr 04 '14 at 08:05
  • @BalusC, just one warning during startup: `WARN [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.` – humungs Apr 04 '14 at 11:54
  • The exception as you have now suggests that OmniFaces' WebXml failed to init during startup, but this should have thrown and logged a runtime exception. Sure there aren't other exceptions in log? – BalusC Apr 04 '14 at 14:28
  • @BalusC, I edited my question and I've added the full WildFly startup log. Only the file upload doesn't work. Other components like datatables, inputs, progress bars are working fine! – humungs Apr 04 '14 at 16:54
  • I also added a screenshot. – humungs Apr 04 '14 at 16:59
  • New information. It works when the uploaded file have less than 10mb size. How can I raise that limit? – humungs May 09 '14 at 18:45
  • Problem solved! Thanks guys! It was a WildFly post limit size. – humungs May 09 '14 at 19:31

4 Answers4

2

Resolved!

WildFly has a 10mb default limit when doing requests. I had to increase that limit. So I opened the file <WILDFLY_HOME>/standalone/conf/standalone.xml and located the following line:

<http-listener name="default" socket-binding="http"/>

And I've added the attribute max-post-size:

<http-listener name="default" socket-binding="http" max-post-size="51200000"/>

And it worked!

humungs
  • 1,144
  • 4
  • 25
  • 44
0

Try this I used in my project and it Worked.

Keep the Bean in @SessionScoped.

If the Bean is used for Uploading Images, Then:

public class ImageController extends BaseWebController implements Serializable{ 

private static final long serialVersionUID = -3975946403680318499L; 
private StreamedContent image;

/**
 * @return the image
 */
public StreamedContent getImage() {

    PeopleDTO people = getCurrentUser();
    byte[] img = people.getUserPhoto();
    if(img != null){
        image = new DefaultStreamedContent(new ByteArrayInputStream(img));
    }else{
        image = null;
    }
    return image;
}

/**
 * @param image the image to set
 */
public void setImage(StreamedContent image) {
    this.image = image;
}

@PostConstruct
public void init() throws FileNotFoundException, IOException{
    image = getImage();
}

/**
 * @author NeelanjanaG
 * @param event
 */
public void handleFileUpload(FileUploadEvent event) {
    UploadedFile uploadedFile = event.getFile();

    byte[] img = uploadedFile.getContents();
    PeopleDTO peopleDTO = getCurrentUser();
    peopleDTO.setUserPhoto(img);
    try {
             new PeopleDAOManager().saveOrUpdate(peopleDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }        
   }
}

Then in your *.xhtml file (in my case) write like:

<h:form prependId="false" id="myProfileForm" enctype="multipart/form-data">
    <h:panelGrid>
        <h:panelGroup layout="block" styleClass="moreInformation">
           <p:fileUpload id="fileUpload" 
                         styleClass="imageStyle" 
                         mode="advanced" dragDropSupport="false" 
                         update="myProfileForm:growl myProfileForm:profileImage" 
                         multiple="false" widgetVar="upload" 
                         sizeLimit="1000000" 
                         fileUploadListener="#{imageController.handleFileUpload}" 
                         allowTypes="/(\.|\/)(gif|jpe?g|png|tiff|exif)$/"/>
        <h:panelGroup>
    </h:panelGrid>
 </h:form>

In your web.xml file please add this:

<mime-mapping>
    <extension>png</extension>
    <mime-type>image/png</mime-type>
</mime-mapping>
<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>

It worked for me fine! Try this and Let me know!

Tiny
  • 27,221
  • 105
  • 339
  • 599
NDeveloper
  • 3,115
  • 7
  • 23
  • 34
  • Thanks, but the problem persists. I changed the scope of my bean to `@SessionScoped` but no luck. The method `save()` is not invoked (with or without `@SessionScoped` or `@ViewScoped`). – humungs Apr 04 '14 at 12:16
0

I had the same issue with jsf 2.2. The following context param solved my issue:

<context-param>
    <param-name>primefaces.UPLOADER</param-name>
    <param-value>commons</param-value>
</context-param>
Tushee
  • 251
  • 2
  • 8
  • I've tried this `context-param`, but no success. I tried with `auto`, `commons` and `native` values. File upload still doesn't work. However, no exception was thrown when I try to upload a file. – humungs Apr 04 '14 at 12:02
-2

Try to add something like this in your web.xml:

<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>
sandris
  • 1,478
  • 2
  • 18
  • 34