File upload do richfaces

Pessoal, boa tarde!
É o seguinte,
já tentei de todo jeito botar o rich:fileUpload pra funcionar, e não consigo :frowning:
o que acontece é o seguinte:
Tudo funciona perfeitamente, até a hora que chega no meu bean, quando eu do um getData() do UploadItem está retornando sempre null, porém o nome do arquivo chega blz.

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" 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" id="WebApp_ID" version="2.5">
 <display-name>InventarioServicos</display-name>
 <!-- SPRING -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
 </context-param>
 <context-param>
  <param-name>facelets.REFRESH_PERIOD</param-name>
  <param-value>2</param-value>
 </context-param>
 <context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>
        /WEB-INF/facelettl.xml
    </param-value>
</context-param>
 
 <!--
 <context-param>
  <param-name>org.richfaces.LoadStyleStrategy</param-name>
  <param-value>NONE</param-value>
 </context-param>
 -->
 <context-param>
  <param-name>org.ajax4jsf.SKIN</param-name>
  <param-value>mcpInventario</param-value>
 </context-param>
 <filter>
  <filter-name>jpaFilter</filter-name>
  <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
 </filter>
 <filter>
  <display-name>Ajax4jsf Filter</display-name>
  <filter-name>ajax4jsf</filter-name>
  <filter-class>org.ajax4jsf.Filter</filter-class>
     <init-param>
		<param-name>createTempFiles</param-name>
		<param-value>true</param-value>
		</init-param>
	<init-param>
		<param-name>maxRequestSize</param-name>
		<param-value>20000000</param-value>
	</init-param>
 </filter>
 <filter-mapping>
  <filter-name>jpaFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>ajax4jsf</filter-name>
  <servlet-name>FacesServlet</servlet-name>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
 </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>
 <servlet>
  <servlet-name>FacesServlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>FacesServlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>FacesServlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
 
<!-- UPLOAD -->
<filter>
<display-name>Sleep Filter</display-name>
<filter-name>sleepFilter</filter-name>
<filter-class>br.gov.pbh.mcp.is.util.SleepDemoFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sleepFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<context-param>
	<param-name>javax.faces.CONFIG_FILES</param-name>
	<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
	<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
	<param-value>client</param-value>
</context-param>
<context-param>
	<param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
	<param-value>false</param-value>
</context-param>
<context-param>
	<param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
	<param-value>false</param-value>
</context-param>
<context-param>
		<param-name>facelets.DEVELOPMENT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.verifyObjects</param-name>
		<param-value>true</param-value>
	</context-param>
</web-app>

então… alguem já conseguiu fazer esse componente rodar redondo??
alguém sabe oq eu estou fazendo errado?

obrigado a todos!

bom dia amigo,
estou tentando fazer funcionar tbm, mas não consigo
aqui não chama o método do fileUploadListener. será que poderia me ajudar?

abs

Também estou com o mesmo problema… O listener não é chamado… Alguem ajuda?

uploadTest.jsp

<%@taglib uri=“http://java.sun.com/jsf/core” prefix=“f”%>
<%@taglib uri=“http://java.sun.com/jsf/html” prefix=“h”%>
<%@ taglib uri=“http://richfaces.org/a4j” prefix=“a4j”%>
<%@ taglib uri=“http://richfaces.org/rich” prefix=“rich”%>

UploadBean.java (managed bean (session))

import java.util.ArrayList;
import java.util.List;

import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;

public class UploadBean {

private List<UploadItem> itens = new ArrayList();	

public void upload(UploadEvent event) {  
	this.itens.add(event.getUploadItem());
	System.out.println("veio arquivo");   // Nunca é chamado....
}  


public List<UploadItem> getItens() {
	return itens;
}

public void setItens(List itens) {
	this.itens = itens;
}

}

web.xml

RichFaces Filter richfaces org.ajax4jsf.Filter createTempFiles true maxRequestSize 10000000

Já perdi umas horas e nada…

Bom pelo que contatei, se você utiliza o rich faces há um bug que será corrigido na próxima versão, pois não chama o listener mesmo. Perdi um dia inteiro para fazer funcionar.

abs!

Pessoal,

No projeto em que trabalho, eu utilizava o RichFaces e o Tomahawk. Ao tirar os filtros do tomahawk e o .jar ele começou a chamar o listener.

Pesquisando encontrei isso: http://www.infoblogs.com.br/view.action?contentId=34184&Incompatibilidades-MyFaces-Tomahawk-e-RichFaces-32

Pode ser que outros filtros do web.xml possa interferir também, a ordem como eles são declarados pode influenciar.

Abraço!

Como você fez pra funcionar andersonsv?
Já mudei versão de jar pra usar aquelas do snapshots.jboss.org, já mexi na ordem dos filtros, até fiz um projeto separado que tem uma página e um bean e nada do listener ser usado.

rafaelld, não consegui não, estou no aguardo de uma nova versão, pois no site já reportaram este problema. É capaz que na proxima versão, já venha corrigido.

abs

Eu não uso nada de tomahawk na aplicação… mas uso o Seam 2.0.0
o meu UploadEvent é chamado, consigo pegar o nome do arquivo, mas o .getData() para pegar o bytes sempre vem null…
não achei a solução tambem… :S

Galera estou como mesmo problema, qual versao nao chama o listener ?? Alguém resolveu ???

Abraços

Alguém ???

[quote=foxpv]Pessoal, boa tarde!
É o seguinte,
já tentei de todo jeito botar o rich:fileUpload pra funcionar, e não consigo :frowning:
o que acontece é o seguinte:
Tudo funciona perfeitamente, até a hora que chega no meu bean, quando eu do um getData() do UploadItem está retornando sempre null, porém o nome do arquivo chega blz.

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" 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" id="WebApp_ID" version="2.5">
 <display-name>InventarioServicos</display-name>
 <!-- SPRING -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
 </context-param>
 <context-param>
  <param-name>facelets.REFRESH_PERIOD</param-name>
  <param-value>2</param-value>
 </context-param>
 <context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>
        /WEB-INF/facelettl.xml
    </param-value>
</context-param>
 
 <!--
 <context-param>
  <param-name>org.richfaces.LoadStyleStrategy</param-name>
  <param-value>NONE</param-value>
 </context-param>
 -->
 <context-param>
  <param-name>org.ajax4jsf.SKIN</param-name>
  <param-value>mcpInventario</param-value>
 </context-param>
 <filter>
  <filter-name>jpaFilter</filter-name>
  <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
 </filter>
 <filter>
  <display-name>Ajax4jsf Filter</display-name>
  <filter-name>ajax4jsf</filter-name>
  <filter-class>org.ajax4jsf.Filter</filter-class>
     <init-param>
		<param-name>createTempFiles</param-name>
		<param-value>true</param-value>
		</init-param>
	<init-param>
		<param-name>maxRequestSize</param-name>
		<param-value>20000000</param-value>
	</init-param>
 </filter>
 <filter-mapping>
  <filter-name>jpaFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>ajax4jsf</filter-name>
  <servlet-name>FacesServlet</servlet-name>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
 </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>
 <servlet>
  <servlet-name>FacesServlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>FacesServlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>FacesServlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
 
<!-- UPLOAD -->
<filter>
<display-name>Sleep Filter</display-name>
<filter-name>sleepFilter</filter-name>
<filter-class>br.gov.pbh.mcp.is.util.SleepDemoFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sleepFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<context-param>
	<param-name>javax.faces.CONFIG_FILES</param-name>
	<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
	<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
	<param-value>client</param-value>
</context-param>
<context-param>
	<param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
	<param-value>false</param-value>
</context-param>
<context-param>
	<param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
	<param-value>false</param-value>
</context-param>
<context-param>
		<param-name>facelets.DEVELOPMENT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.verifyObjects</param-name>
		<param-value>true</param-value>
	</context-param>
</web-app>

então… alguem já conseguiu fazer esse componente rodar redondo??
alguém sabe oq eu estou fazendo errado?

obrigado a todos![/quote]

Então se vc definir no web.xml o reateTempFiles como true… o seu getData vai retornar null mesmo… deixe o reateTempFiles como false… para retornar algum valor no getData

O meu problema é que não está chamando o listener, tendeu ???

é só depois que eu vi…
de uma olhada de como esta o meu:

<rich:fileUpload fileUploadListener="#{contratoController.uploadArquivos}" maxFilesQuantity="5" id="upload" immediateUpload="false" acceptedTypes="jpg, gif, png, bmp, pdf" allowFlash="true" > <a4j:support event="onuploadcomplete" reRender="info,table" /> </rich:fileUpload>

/** * Método que adiciona os arquivos numa lista * @param event */ public void uploadArquivos(UploadEvent event) { itens.add(event.getUploadItem()); }

web.xml

<filter> <display-name>RichFaces Filter</display-name> <filter-name>richfaces</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> <init-param> <param-name>createTempFiles</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>maxRequestSize</param-name> <param-value>20000000</param-value> </init-param> </filter>

ve se ajuda ai…

Vou ver, valeu ! Mas que versão do rich faces tá usando ??

richfaces-ui-3.3.0.GA.jar

A mesma que eu valeu !

Pessoal é simples. Para se utilizar o getData() os dados devem estar na “RAM”. Por Default é configurado para salvar em uma pasta “temporária”. Para salvar na RAM basta configurar o seu web.xml da seguinte forma:



Ajax4jsf Filter
ajax4jsf
org.ajax4jsf.Filter

createTempFiles
[color=red]false[/color]


Agora é o getData() não irá retornar null