0

I recived error when try upload file using p:fileUpload. I tried maven clean and maven install for update dependeces. I changed web.xml many times. I belive the problem is relationship with my anotation, i m using @Autowired (Spring) but i change it an donsen't work. How i resolve this problem?

I m using: Primefaces 6.0, Java 8, Spring Data, Spring MVC

my 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>
    <url-pattern>*.jsf</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ASYNC</dispatcher>
</filter-mapping>

JSF:

<p:fileUpload id="fileDescAto" auto="true" multiple="false"
    invalidFileMessage="Tipo de Arquivo Inválido:"
    disabled="#{not empty searchDocumentoBean.descAtoArquivoFileName}"
    update="messagesDialog @this panelGroupFileDescription"
    allowTypes="/(\.|\/)(pdf)$/" sizeLimit="10485760"
    invalidSizeMessage="Tamanho de arquivo excedido (10MB):"
    fileUploadListener="#{searchDocumentoBean.adicionaArquivoUpload}"
    label="Escolher Arquivo..." mode="advanced" />

Bean:

public void adicionaArquivoUpload(FileUploadEvent ev) {

        String[] name = ev.getFile().getFileName().split("\\\\");

        descAtoArquivo = ev.getFile().getContents();
        descAtoArquivoFileName = name[name.length-1];
    }

    public void removeArquivoUpload() {

        descAtoArquivo = null;
        descAtoArquivoFileName = null;
    }// GET AND SET OMITED

Head annotation My bean:

@Component
@Scope("view")
@ManagedBean(name = "searchDocumentoBean")
@URLMappings(mappings = {       
        @URLMapping(id ="searchDocumento", pattern = "/searchDocumento", viewId = "/resources/pages/documento/searchDocumento.jsf")
})

ERROR CONSOLE WHEN I TRY USE FILE UPLOAD

javax.faces.event.AbortProcessingException error obtained during the processing of RENDER_RESPONSE 6: UIComponent-ClientId

08:43:55,231 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-/0.0.0.0:8080-2) Error Rendering View[/resources/pages/documento/searchDocumento.xhtml]: javax.faces.event.AbortProcessingException: java.lang.NullPointerException
    at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:303) [primefaces-6.0.jar:6.0]
    at org.primefaces.context.PrimePartialResponseWriter.startUpdate(PrimePartialResponseWriter.java:142) [primefaces-6.0.jar:6.0]

Caused by: java.lang.NullPointerException
    at org.primefaces.util.ResourceUtils.filterStylesheets(ResourceUtils.java:96) [primefaces-6.0.jar:6.0]
    at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:287) [primefaces-6.0.jar:6.0]
    ... 49 more


08:43:55,246 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-/0.0.0.0:8080-2) JSF1073: javax.faces.event.AbortProcessingException obtido durante o processamento de RENDER_RESPONSE 6: UIComponent-ClientId=, Message=java.lang.NullPointerException
08:43:55,240 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-/0.0.0.0:8080-5) Error Rendering View[/resources/pages/documento/searchDocumento.xhtml]: javax.faces.event.AbortProcessingException: java.lang.NullPointerException

UPDATE 27/09/2017 I recive error: JBWEB000281: Servlet mapping specifies an unknown Servlet name Faces Servlet´

Where an error in my web.xml?

<servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
<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>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping> 

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

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
paulo.sobrinho
  • 83
  • 1
  • 1
  • 11
  • Start here: https://stackoverflow.com/questions/18387993/spring-jsf-integration-how-to-inject-a-spring-component-service-in-jsf-managed (it is a duplicate imo) – Kukeltje Sep 25 '17 at 15:22
  • So what about the info in the link I posted? – Kukeltje Sep 25 '17 at 21:23
  • I have already visited this link, it does not solve my problem, I already tried to change the annotation (when applicable), but it did not solve my problem with p:fileUpload. I wonder if there is any other configuration needed. I've visited the Primefaces page to look for additional information, but the implementation of web.xml, bean, and jsf seem to match that presented on the sweb site. – paulo.sobrinho Sep 26 '17 at 11:16
  • I believe it's the dependency injection problem using 'Autowired', as this is the only difference I'm finding in my searches on the forums on the internet. I also tried the Primefaces forum, but I got no response if using 'Autowired' is associated with the malfunction of the primefaces component. – paulo.sobrinho Sep 26 '17 at 11:27
  • Regardless of all this, in the link I posted, it clearly states that using `@Component` AND `@ManagedBean` on a class at the same time is **wrong** – Kukeltje Sep 26 '17 at 11:53
  • ok, it states `@component` but the 'issue' is the same – Kukeltje Sep 26 '17 at 11:54
  • I believe I know the cause of the problem however I'm getting a Servlet error mapping specifies an unknown Servlet name Faces Servlet. please see UPDATE 27/09/2017. Thank You so much – paulo.sobrinho Sep 27 '17 at 14:52
  • Remove the faces servlet mapping as you do not seem to have (or need) one – Kukeltje Sep 27 '17 at 15:26
  • i solve my problem: https://stackoverflow.com/questions/15659071/listener-method-in-pfileupload-is-never-invoked-in-primefaces – paulo.sobrinho Sep 28 '17 at 18:03
  • Thank You Kukeltje – paulo.sobrinho Sep 28 '17 at 18:09

1 Answers1

0

This solve my problem:

Listener method in p:fileUpload is never invoked in primefaces

Besides That. i need especify location the Faces Servlet:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>

javax.faces.webapp.FacesServlet

I needed especify resource primefaces depends for fileupload works fine>

<context-param>
        <param-name>primefaces.UPLOADER</param-name>
        <param-value>commons</param-value>
 </context-param>

In some versions of primefaces it is not necessary to specify this configuration. I am currently using version 6.0, which believed that this specification was not necessary in web.xml because it is a newer version, but it was necessary.

paulo.sobrinho
  • 83
  • 1
  • 1
  • 11