[Resolvido]Mostrar mensagem na tela JSF rich upload

1 resposta
F

Bom dia galera!
Então estou com um problema. Estou querendo mostrar uma mensagem na tela quando o usuário estiver upando um arquivo q já está upado. Tipo “ARQUIVO JÁ IMPORTADO”.
Aqui vai os códigos:

método da importação:

/**
	 * Ação para upload de arquivos de Cronograma.
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void uploadListenerCronograma(UploadEvent event) {
//		boolean doUpload = true;
		UploadItem item = event.getUploadItem();
		FileDTO dto = new FileDTO(item.getFile());
		dto.setData(item.getData());
		files.add(dto);

		String fileName = FileUtils.getNomeArquivo(item.getFileName());
		String filePath = "OP" + getOperacao().toString() + "_"
				+ FILEPATH_CRONOGRAMA;
		String categoria = CATEGORIA_CRONOGRAMA;
		// Retira os acentos da string.
		fileName = RemoverAcentos.remover(fileName);

		Operacao op = new Operacao();
		op.setId(getOperacao());

		Upload upload = new Upload();
		upload.setName(fileName);
		upload.setDate(new Date(System.currentTimeMillis()));
		upload.setFileName(fileName);
		upload.setFilePath(filePath);
		upload.setFileSize(new Double(item.getFileSize()));
		upload.setCategoria(categoria);
		upload.setOperacao(op);

		try {
//			List<Upload> uploadList = null;
//			uploadList = facade.getListUploadsByCategoria(CATEGORIA_CRONOGRAMA);
//			Iterator<Upload> iter = uploadList.iterator();
//			while (iter.hasNext()) {
//				Upload up = iter.next();
//				if(fileName.equalsIgnoreCase(up.getFileName()))
//					doUpload = false;
//			}
//			if(doUpload)
//			{
			facade.uploadFile(fileName, filePath, FileUtils
					.getBytesFromFile(item.getFile()), "", "", "", upload);
//			}else{
//				log.warn("ImportacaoBean.uploadListenerCronograma - Warn - " + getMessageBundleByKey("comum.msg.mesmoNomeArquivo", null));
//				addMensagemAviso(getMessageBundleByKey("comum.msg.mesmoNomeArquivo", null));
//			}
			addMensagemAviso(this.getMensagem());

		} catch (PromonBusinessException e) {
			log.error(e.getMessage());
			addMensagemErro(e.getMessage());
		} catch (IOException e) {
			log.error(e.getMessage());
			addMensagemErro(e.getMessage());
		} catch (Exception e) {
			log.error(e.getMessage());
			addMensagemErro(e.getMessage());
		}
	}

página do 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:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">
<body>
<ui:composition template="/jsp/template.xhtml">
	<ui:define name="title">
		<div>
			<h:outputText value="#{msg['menu.configuracao.operacao.importarCronograma']}" styleClass="fonteTitulo" />
		</div>
	</ui:define>

	<ui:define name="body">

		<rich:messages 
			id="mensagensTela" 
			ajaxRendered="true" 
			errorClass="msg_erro" 
			infoClass="msg_sucesso"
			warnClass="msg_aviso" 
			labelClass="msg_sucesso" />

		<rich:panel header="#{msg['comum.arquivo.upload']}">

			<h:panelGrid columns="2">

				<h:column>
					<h:panelGrid columns="2" id="panel">
						<rich:fileUpload id="file"
							fileUploadListener="#{importacaoBean.uploadListenerCronograma}"
							immediateUpload="false" 
							maxFilesQuantity="5" 
							autoclear="false"
							addControlLabel="#{msg['importar.adicionar']}"
							stopControlLabel="#{msg['importar.parar']}"
							cancelEntryControlLabel="#{msg['importar.cancelar']}"
							transferErrorLabel="#{msg['importar.erro']}"
							doneLabel="#{msg['importar.concluido']}"
							progressLabel="#{msg['importar.progresso']}"
							clearControlLabel="#{msg['importar.limpar']}" 
							noDuplicate="true"
							clearAllControlLabel="#{msg['importar.limparTudo']}"
							allowFlash="false" 
							listHeight="200px" 
							listWidth="370px"
							disabled="#{!importacaoBean.manter}">
							<f:facet name="label">
								<h:outputText value="{_KB}KB de {KB}KB --- {mm}:{ss}" />
							</f:facet>
							<a4j:support event="onuploadcomplete" reRender="table, labelMsg" />
						</rich:fileUpload>
					</h:panelGrid>
				</h:column>

				<h:column>
					<rich:scrollableDataTable 
						id="table" 
						value="#{importacaoBean.itensUploadCronograma}" 
						var="item"
						width="580px" height="200px"
						onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
						onRowMouseOut="this.style.backgroundColor='#{transparent}'"
						sortMode="single">
						<f:facet name="header">
							<h:outputText value="#{msg['importar.arquivos']}"></h:outputText>
						</f:facet>

						<rich:column width="50px" sortExpression="#{item.seq}">
							<f:facet name="header">
								<h:outputText value="id" />
							</f:facet>
							<h:outputText value="#{item.seq}" />
						</rich:column>

						<rich:column width="265px" sortExpression="#{item.fileName}">
							<f:facet name="header">
								<h:outputText value="#{msg['importar.nomeArquivo']}" />
							</f:facet>
							<h:outputText value="#{item.fileName}" />
						</rich:column>

						<rich:column width="80px" sortExpression="#{item.fileSize}">
							<f:facet name="header">
								<h:outputText value="#{msg['importar.tamanho']}" />
							</f:facet>
							<h:outputText value="#{item.fileSize} kb" />
						</rich:column>

						<rich:column width="80px" sortable="false">
							<f:facet name="header">
								<h:outputText value="#{msg['importar.excluir']}" />
							</f:facet>
							<a4j:commandLink action="#{importacaoBean.doDelete}"
								value="Excluir" reRender="table" disabled="#{!importacaoBean.manter}"/>
						</rich:column>

						<rich:column width="80px" sortable="false">
							<f:facet name="header">
								<h:outputText value="#{msg['importar.download']}" />
							</f:facet>
							<a4j:commandLink action="#{importacaoBean.doDownload}"
								value="download" reRender="table, panelDownload" disabled="#{!importacaoBean.manter}" />
						</rich:column>

					</rich:scrollableDataTable>
				</h:column>				
			</h:panelGrid>

			<h:panelGrid id="panelDownload">
				<f:verbatim rendered="#{importacaoBean.renderDownload}">
					<iframe 
						src="#{importacaoBean.urlArquivoDownload}" 
						width="100%"
						height="1200px" 
						frameborder="0" 
						style="height: 0px; width: 0px">
					</iframe>
				</f:verbatim>
			</h:panelGrid>
		</rich:panel>
	</ui:define>
</ui:composition>
</body>
</html>

Vlw!

1 Resposta

F

Resolvido. Foi só colocar uma action dentro do a4j support. Coisinha chata…

Criado 28 de abril de 2010
Ultima resposta 29 de abr. de 2010
Respostas 1
Participantes 1