GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Erro com upload de arquivo primeFaces

exception
jsf
Tags: #<Tag:0x00007f00916c46c8> #<Tag:0x00007f00916c4560>

#1
java.lang.NoSuchMethodError: org.primefaces.util.ResourceUtils.getComponentResources

Sou nova com JSF e estou tentando criar um “hello word” com upload de arquivos usando PrimeFaces, mas só estou pegando essa exceção.
Já tentei buscar na net o que poderia ser, mas não achei muita coisa. Alguém sabe como resolver?

minha página:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"  
 xmlns:h="http://java.sun.com/jsf/html"  
 xmlns:f="http://java.sun.com/jsf/core"  
 xmlns:p="http://primefaces.org/ui">  

 <h:head><title>reCOVER</title></h:head>      
 <h:body>      	
	<h:form id="form" enctype="multipart/form-data">    		
		<p:fileUpload fileUploadListener="#{loadProjects.handleFileUpload}" />
	</h:form>
 </h:body>  
</html> 

Meu bean:

package jsf;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

@ManagedBean
@SessionScoped
public class LoadProjects {

public void handleFileUpload(FileUploadEvent event){
	UploadedFile file = event.getFile();
}

}


stacktrace:
java.lang.NoSuchMethodError: org.primefaces.util.ResourceUtils.getComponentResources(Ljavax/faces/context/FacesContext;)Ljava/util/ArrayList;
at org.primefaces.application.resource.DynamicResourcesPhaseListener.afterPhase(DynamicResourcesPhaseListener.java:31)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Jan 02, 2017 12:06:53 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
Grave: java.lang.NoSuchMethodError: org.primefaces.util.ResourceUtils.getComponentResources(Ljavax/faces/context/FacesContext;)Ljava/util/ArrayList;
at org.primefaces.application.resource.DynamicResourcesPhaseListener.afterPhase(DynamicResourcesPhaseListener.java:31)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)


#2

Eu conheço uma outra implementação de p:fileUpload.
Conheço a que está no demo na página do primefaces

Nessa implementação temos um atributo do tipo UploadedFile e através do setter o prime faz esse atributo conter o arquivo selecionado.


#3
Como esta seu 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>

<p:fileUpload id=“fileupload” fileUploadListener="#{manutProcesso.upload2}" widgetVar="fileupload"
label=“Selecionar” uploadLabel=“Guardar arquivo em Lote” cancelLabel="Cancelar"
mode=“advanced” update=“manutProcesso”/>


#4

Igor, acontece que meu objetivo é carregador múltiplos arquivos, por isso estou usando o fileUploadListener.

Mas mesmo usando a outra maneira com os getters e setters tenho outro exceção:
java.lang.NoSuchMethodError: org.primefaces.context.ApplicationContext.getCurrentInstance()Lorg/primefaces/context/ApplicationContext;
at org.primefaces.webapp.PreDestroyApplicationEventListener.processEvent(PreDestroyApplicationEventListener.java:30)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2187)
at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:2163)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:296)
at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:314)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4805)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5453)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3887)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:424)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1310)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1496)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1506)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1506)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1485)
at java.lang.Thread.run(Thread.java:744)


#5

DougF, não estou usando o filter, meu web.xml está assim:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com /xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>recoverweb</display-name>
 <welcome-file-list>
<welcome-file>index.html</welcome-file>
 <welcome-file>index.htm</welcome-file>
 <welcome-file>index.jsp</welcome-file>
 <welcome-file>default.html</welcome-file>
 <welcome-file>default.htm</welcome-file>
 <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
 <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
</context-param>
<context-param>
 <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
 <param-value>resources.application</param-value>
</context-param>

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

<listener>
 <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>

#6

Mesmo colocando o filter, acontece o mesmo erro.


#7

Entendi.

De fato, a exception é do pacote java.lang, logo é independente do prime…
Ele só não tá encontrando o método…

Vou pensar mais um pouco aqui hehe.


#8

Por acaso você está usando o Weblogic?


#9

Vc importou as seguintes dependências?

commons-fileupload 1.3
commons-io 2.2


#10

Não


#11

Só a commons-fileupload.
Testei agora com a commons-io, mas não fez diferença :frowning:


#12

Resolvido!


#13

Poste a solução pro caso de mais alguém precisar, por favor.


#14

Eu estava usando uma biblioteca mais antiga do PrimeFaces. Atualizei para a 6.0 e corrigiu o problema.


#15

@DeniseDAC , caso você vem a usar Pretty-faces em seu projeto, existe um processo de configuração para upload com Primefaces pouco conhecido.
Leia: https://medium.com/@davidfaustinoeng/upload-primefaces-pretty-faces-e-tomcat-e-form-multipart-form-data-4b16d3669a7