[resolvido] problema FileUploadEvent

1 resposta
M

bom dia... estou tentando fazer um crud de arquivos com jsf,

Meu bean

package br.com.projeto.controller;

import java.io.FileOutputStream;
import java.io.IOException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.event.FileUploadEvent;

import br.com.projeto.beans.Arquivos;

@SessionScoped
@ManagedBean
public class FileUploadController {

	private Arquivos arquivos = new Arquivos();

	
		public void fileUploadAction(FileUploadEvent event) throws IOException {  
			System.out.println("----> fileUploadAction(FileUploadEvent event)");  
			    System.out.println("---->fileUploadAction(FileUploadEvent event)");  
			    arquivos.setNome(event.getFile().getFileName());  
			  
			    System.out.println("----> nome do arquivo selecionado: " + arquivos.getNome());  
			  
			    byte[] conteudo = event.getFile().getContents();  
			  
			    String caminho = "C:\\arquivos" + event.getFile().getFileName();  
			    FileOutputStream fos = new FileOutputStream(caminho);  
			    fos.write(conteudo);  
			    fos.close();  
			  
			   
			}  
		
	

	public Arquivos getArquivos() {
		return arquivos;
	}

	public void setArquivos(Arquivos arquivos) {
		this.arquivos = arquivos;
	}

}

meu jsf

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<h:head>
	<title>Arquivos</title>
</h:head>
<h:body>

	<h:form id="form">
		<div align="center">
			<p:panel header="Arquivos" style="width:1050px">
				<ui:include src="/paginas/Menu.xhtml"></ui:include>

				<p:messages showDetail="true" />

				<p:fileUpload id="idFileUpload"  
                           auto="true"  
                         label="Procurar..."  
                         allowTypes="*.*"  
                         multiple="false"  
  
                         fileUploadListener="#{fileUploadController.fileUploadAction}"  
                         update="idMeuForm"  />  

			</p:panel>
		</div>
	</h:form>
</h:body>
</html>

o problema é que quando eu clico em upload ele não faz nada não me da erro e não faz upload...

alguem?

1 Resposta

M

consegui faltava colocar no web xml

filter>
PrimeFaces FileUpload Filter
org.primefaces.webapp.filter.FileUploadFilter

thresholdSize
51200


uploadDirectory
C:\arquivos



PrimeFaces FileUpload Filter
Faces Servlet

Criado 10 de janeiro de 2012
Ultima resposta 10 de jan. de 2012
Respostas 1
Participantes 1