Quantcast
Channel: GUJ - Tópicos com a tag primefaces
Viewing all articles
Browse latest Browse all 578

JSF 2.2 UploadFile com StreamedContent não renderiza imagem

$
0
0

@bergwin escreveu:

Boa Tarde, já procurei em muitos lugares e não consigo encontrar uma solução para fazer upload e mostrar antes de comitar, não aparece nenhum erro, só mostra a imagem quebrada, agradeço desde já a atenção e ajuda de todos, segue abaixo partes dos códigos relacionados

Classe Modelo
public StreamedContent getImagem() {
     FacesContext context = FacesContext.getCurrentInstance();
     if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
         return new DefaultStreamedContent();
     } else {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
 	return new DefaultStreamedContent(new ByteArrayInputStream(content), contentType);
     }
 }           
 public void handleFileUpload(FileUploadEvent event) {
      Foto foto = new Foto();
      for (Foto f : orcamentoItem.getFotos()) {
		if (f.getNome().equals(event.getFile().getFileName())) {
		    foto = f;
		}
	    }
	    foto.setNome(event.getFile().getFileName());
	    foto.setContent(event.getFile().getContents());
        foto.setContentType(event.getFile().getContentType());
	    orcamentoItem.getFotos().add(foto);
	} 
 Páginas XHTML
 	<h:outputText value="Imagens" />
<p:fileUpload  fileUploadListener="#{orcamentoBean.handleFileUpload}"
    update="lighbox1" mode="advanced" auto="true"
    allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

     <p:lightBox styleClass="imagebox" id="lighbox1">
     <ui:repeat value="#{orcamentoBean.orcamentoItem.fotos}" var="var">
          <p:graphicImage value="#{var.imagem}" />
     </ui:repeat>
     </p:lightBox>

Abraços!

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 578


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>