Rich:upload + não funciona!

1 resposta
Ginhu

Galera,

Estou tentando fazer um upload de arquivo, mas qdo clico em upload, o mesmo não tá chamando meu método no BEAN, alguém tem alguma idéia do que possa ser ???

meu .xhtml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">


	<h:panelGrid id="pgVersao" columns="2" >
		<h:outputText value="Código:" />
        <h:inputText size="10" value="#{versaoMB.versao.versId}" /> 
		<h:outputText value="Build:" />
        <h:inputText size="3" value="#{versaoMB.txtbuild}" /> 
        <h:outputText value="Descrição:" />
        <h:inputText size="50" value="#{versaoMB.txtversao}" />  
        <h:outputText value="Status:" />
        <h:selectOneMenu	 
        				value="#{versaoMB.statusId}">
		    <f:selectItems value="#{configuradorMB.status}"/>
		</h:selectOneMenu>  
        <h:outputText value="Caminho:" />
        <h:inputText  size="100" value="#{versaoMB.txtpath}" readonly="true" disabled="false"  />  		
		<h:outputText value="Arquivo:" />
		<rich:fileUpload 	id="upload"
		 
							acceptedTypes="war" 
							listHeight="70px" 
							listWidth="715px"
				 			autoclear="false"
				 			addControlLabel="Adicionar"
				 			clearAllControlLabel="Remover"
				 			stopControlLabel="Parar"
				 			cancelEntryControlLabel="Parar"
				 			uploadControlLabel="Transferir"	 	
				 			progressLabel="Transferindo..."
				 			transferErrorLabel="Erro ao transferir arquivo, tente novamente!"		 
				 			doneLabel="Terminou"
				 			rendered="true"
				 			fileUploadListener="#{versaoMB.upload}">		 			
	        <a4j:support event="onuploadcomplete" reRender="camVersao" />              
	           
			<f:facet name="label">
				<h:outputText value="{_KB}KB from {KB}KB tr --- {mm}:{ss}" />
			</f:facet>		
			
	    </rich:fileUpload>
	</h:panelGrid>
</ui:composition>

meu MB:

package com.diebold.medial.configurador.web.controller;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.faces.component.html.HtmlSelectOneMenu;

import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.diebold.medial.configurador.db.dao.imp.VersaoDao;
import com.diebold.medial.configurador.db.entity.Versao;
import com.diebold.medial.configurador.util.FileManager;


@Controller("versaoMB")
@Scope("session")
public class VersaoMB{
	@Resource
	private 	VersaoDao			versaoDao;
	
	private  	HtmlSelectOneMenu	statusId;
	private  	Versao	   			versao;
	private  	String				txtPesquisa ;	
	private 	String 				txtversao;
	private 	String 				txtbuild;
	private 	String 				txtpath;
	private 	String				versaoId;
	
	public VersaoMB() {
		versao = new Versao();
	}
	
	public VersaoDao getVersaoDao() {
		return versaoDao;
	}



	public void setVersaoDao(VersaoDao versaoDao) {
		this.versaoDao = versaoDao;
	}



	public HtmlSelectOneMenu getStatusId() {
		return statusId;
	}



	public void setStatusId(HtmlSelectOneMenu statusId) {
		this.statusId = statusId;
	}



	public Versao getVersao() {
		return versao;
	}



	public void setVersao(Versao versao) {
		this.versao = versao;
	}



	public String getTxtPesquisa() {
		return txtPesquisa;
	}



	public void setTxtPesquisa(String txtPesquisa) {
		this.txtPesquisa = txtPesquisa;
	}



	public String getTxtversao() {
		return txtversao;
	}



	public void setTxtversao(String txtversao) {
		this.txtversao = txtversao;
	}



	public String getTxtbuild() {
		return txtbuild;
	}



	public void setTxtbuild(String txtbuild) {
		this.txtbuild = txtbuild;
	}



	public String getTxtpath() {
		return txtpath;
	}



	public void setTxtpath(String txtpath) {
		this.txtpath = txtpath;
	}



	public String getVersaoId() {
		return versaoId;
	}



	public void setVersaoId(String versaoId) {
		this.versaoId = versaoId;
	}


	public void clear(){
		this.versao.setVersPath("");
		this.versao.setVersBuild((short)0);
		this.versao.setVersDs("");
	}
	public void novaVersao(){
		this.versao = new Versao();		
	}
	public List<Versao> getTodos() {
		System.out.println("["+this.getClass().getName()+"](getTodos)");
		return	versaoDao.findAll();			
	}	
 
	public String save(){
		System.out.println("["+this.getClass().getName()+"](save)");
		try {		
	        Date date = new Date();       
	     
	        this.versao.setVersSt(this.statusId.getValue().toString());       
			this.versao.setVersCdUsuario("ADMMEDIAL");
			this.versao.setVersDtAtz(date);
			this.versao.setVersBuild((short)Integer.parseInt(this.txtbuild));
			
			this.versaoDao.update(versao);
		}catch(Exception ex){
			System.out.println("["+this.getClass().getName()+"](save):" + ex.getMessage());
		}
		return "sucess";
	}
	public Versao getRegistro() {
		System.out.println("["+this.getClass().getName()+"](getRegistro)");
		
		return (Versao) this.versaoDao.findByKey(versaoId);
	}
	
	public String edit() {
		System.out.println("["+this.getClass().getName()+"](edit)");
		setVersao(this.getRegistro());
		
		return "sucess";
	}
	public String deletar(){
		System.out.println("["+this.getClass().getName()+"](deletar)");
		this.versaoDao.delete(this.getRegistro());
		return "sucess";
	}
	public String upload(UploadEvent event) throws IOException,  FileNotFoundException { 

	    try { 
	    		    	
	    	String dsFolder = getTxtversao() + " " +getTxtbuild();	
	    	
	    	System.out.println("dsFodler: " + dsFolder);
	    	
	    	FileManager		fileManager = new FileManager();
	    	UploadItem 		item 		= event.getUploadItem();  

	    	
	    	String caminho = fileManager.saveFile(item, dsFolder);
	    	
	    	this.setTxtpath(caminho);
	    	System.out.println("Caminho" + caminho);
	    	
	    }catch (UnknownHostException ex) {
	    	System.out.println("["+this.getClass().getName()+"](upload):" + ex.getMessage());

	    } catch (Exception ex) { 
	    	System.out.println("["+this.getClass().getName()+"](upload):" + ex.getMessage());
	    } 
	    return "sucess";
	}
}

Agradeço desde já, obrigado…

1 Resposta

mateusprado

De uma olhada:

http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf?c=fileUpload&tab=usage

[]s,

Criado 2 de março de 2009
Ultima resposta 2 de mar. de 2009
Respostas 1
Participantes 2