Type components allows <p:dataTable/> Lists "StreamedContent

UI Components for JSF
Post Reply
Erickfm8
Posts: 56
Joined: 22 Jun 2010, 14:25

05 Apr 2011, 17:14

I use the FileUpload to complete the upload and then I put on a list, insert the data in the list works, just the image does not appear.

I could not run the following code

.xhtml

Code: Select all

<?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">  
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:p="http://primefaces.prime.com.tr/ui"  
      xmlns:f="http://java.sun.com/jsf/core">  
    <h:head>  
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />  
        <title>Cadastro de Album</title>  
    </h:head>  
    <f:view>  
        <h:body>  
            <h:form id="frmGridAlbum">  
                <p:growl id="menssagensAlbum"  
                         life="3000"/>  
                <p:dataTable id="dtAlbuns"  
                             widgetVar="dtAlbuns"  
                             var="album"  
                             value="#{albumMB.albuns}"  
                             paginator="true"  
                             rows="5"  
                             selection="#{albumMB.album}"  
                             selectionMode="single"  
                             onRowSelectComplete="dlgAlbum.show();"  
                             emptyMessage="Nao existe Album cadastrado"  
                             style="width:60%"  
                             update="frmCadastroAlbum:somCliente, frmCadastroAlbum:itaDescricao, frmCadastroAlbum:dgdFotos, frmCadastroAlbum:clkGravar, frmCadastroAlbum:clkAlterar">  
                    <p:column sortBy="#{album.id}"  
                              filterBy="#{album.id}">  
                        <f:facet name="header">  
                            <h:outputText value="Id" />  
                        </f:facet>  
                        <h:outputText value="#{album.id}" />  
                    </p:column>  
                    <p:column sortBy="#{album.cliente.nome}"  
                              filterBy="#{album.cliente.nome}">  
                        <f:facet name="header">  
                            <h:outputText value="Cliente" />  
                        </f:facet>  
                        <h:outputText value="#{album.cliente.nome}" />  
                    </p:column>  
                </p:dataTable>  
                <p:panel style="width:59.2%">  
                    <p:commandLink id="clkIncluir"  
                                   title="Incluir"  
                                   oncomplete="dlgAlbum.show()"  
                                   action="#{albumMB.incluir}"  
                                   update="frmCadastroAlbum:somCliente, frmCadastroAlbum:itaDescricao, frmCadastroAlbum:dgdFotos, frmCadastroAlbum:clkGravar, frmCadastroAlbum:clkAlterar">  
                        <h:graphicImage url="/imagens/novo.jpg"  
                                        style="border:0"/>  
                    </p:commandLink>  
                    <p:commandLink title="Apagar"  
                                   actionListener="#{albumMB.apagar}"  
                                   style="margin-left:20px"  
                                   update="frmGridAlbum"  
                                   oncomplete="dlgAlbum.hide();">  
                        <h:graphicImage url="/imagens/apagar.jpg"  
                                        style="border:0"/>  
                    </p:commandLink>  
                    <h:commandLink title="Voltar"  
                                   action="#{albumMB.voltar}"  
                                   style="margin-left:20px">  
                        <h:graphicImage url="/imagens/voltar.jpg"  
                                        style="border:0"/>  
  
                    </h:commandLink>  
                </p:panel>  
            </h:form>  
            <h:form id="frmCadastroAlbum">  
  
                <p:dialog id="dlgAlbum"  
                          widgetVar="dlgAlbum"  
                          header="Album"  
                          width="700">  
                    <h:outputLabel value="imagem"  
                                   for="gi"/>  
                    <p:graphicImage id="gi" value="#{albumMB.imagem}"/>  
                    <h:panelGrid columns="2">  
                        <h:outputLabel value="Cliente:"  
                                       for="somCliente" />  
                        <h:selectOneMenu id="somCliente"  
                                         value="#{albumMB.album.cliente.nome}"  
                                         required="true"  
                                         requiredMessage="Informe a descricao">  
                            <f:selectItems value="#{albumMB.clientes}"  
                                           var="cliente"  
                                           itemValue="#{cliente.id}"  
                                           itemLabel="#{cliente.nome} CPF : #{cliente.cpf}"/>  
                        </h:selectOneMenu>  
                        <h:outputLabel value="Descricao:"  
                                       for="itaDescricao"/>  
                        <p:inputTextarea id="itaDescricao"  
                                         value="#{albumMB.album.descricao}"  
                                         required="true"  
                                         requiredMessage="Informe a descricao"/>  
                    </h:panelGrid>  
                    <p:dataGrid id="dgdFotos"  
                                var="imagem"  
                                value="#{albumMB.imagens}"  
                                columns="2"  
                                rows="1"  
                                paginator="true"  
                                style="width:30%">  
                        <p:column>  
                               <p:graphicImage id="gii"   
                                               value="#{imagem}"/>  
                        </p:column>  
                    </p:dataGrid>  
                    <h:panelGrid columns="3" >  
                        <p:fileUpload id="fudSelecionarFotos"  
                                      fileUploadListener="#{albumMB.selecionarFoto}"  
                                      multiple="true"  
                                      allowTypes="*.jpg;*.png;*.gif;"  
                                      description="Images"  
                                      update="dgdFotos, gi"  
                                      style="margin-right:20px"/>  
                        <p:commandLink  id="clkGravar"  
                                        title="Gravar"  
                                        action="#{albumMB.gravar}"  
                                        disabled="#{!empty albumMB.album.id}"  
                                        style="margin-right:20px"  
                                        update="frmCadastroAlbum:somCliente, frmCadastroAlbum:itaDescricao, frmCadastroAlbum:dgdFotos, frmGridAlbum:menssagensAlbum, frmGridAlbum:dtAlbuns">  
                            <h:graphicImage url="/imagens/gravar.jpg"  
                                            style="border:0"/>  
                        </p:commandLink>  
                        <p:commandLink id="clkAlterar"  
                                       title="Alterar"  
                                       action="#{albumMB.album}"  
                                       disabled="#{empty albumMB.album.id}"  
                                       update="frmCadastroAlbum:somCliente, frmCadastroAlbum:itaDescricao, frmCadastroAlbum:dgdFotos, frmGridAlbum:menssagensAlbum, frmGridAlbum:dtAlbuns"  
                                       style="margin-left:20px">  
  
                            <h:graphicImage url="/imagens/alterar.bmp"  
                                            style="border:0"/>  
  
                        </p:commandLink>  
                    </h:panelGrid>  
  
                </p:dialog>  
            </h:form>  
        </h:body>  
    </f:view>  
</html>  




MB

Code: Select all

private List<StreamedContent> imagens = new ArrayList<StreamedContent>();

// Get e Set ...

//...............

public void selecionarFoto(FileUploadEvent event) throws IOException {  
      System.out.println("okkk");  
  
      UploadedFile uf = event.getFile();  
      String nomeArquivo = uf.getFileName();  
      InputStream is = null;  
      Foto foto = new Foto();  
      String caminho = "C:"+File.separator+"img"+File.separator+nomeArquivo;  
    try {  
          is = uf.getInputstream();  
          byte[] b = new byte[is.available()];  
          InputStream stream = new ByteArrayInputStream(b);  
          foto.setNome(nomeArquivo);  
          foto.setFoto(b);  
          //BufferedImage img = ImageIO.read(event.getFile().getInputstream());  
          //File file = new File(caminho);  
          //boolean write = ImageIO.write(img, "jpg", file);  
          //FileInputStream fi = new FileInputStream(file);  
          //System.out.println("escreveu?? " +write);  
          this.imagem = new DefaultStreamedContent(stream);  
          this.getImagens().add(new DefaultStreamedContent(stream));  
          foto.setImagem(new DefaultStreamedContent(stream));  
           
           
          //foto.setImagem(new DefaultStreamedContent(stream));  
          //foto.setImagem(new DefaultStreamedContent(event.getFile().getInputstream()));  
          fotos.add(foto);  
          //this.imagem = new DefaultStreamedContent(stream);  
          System.out.println("okkk nome"+ foto.getImagem());  
          JSFUtil.enviarMenssagemSucesso("Upload realizado com sucesso.");  
      } catch (Exception e) {  
          e.printStackTrace();  
          JSFUtil.enviarMenssagemErro("Erro ao realizar o Upload.");  
      } finally {  
          try {  
              is.close();  
          } catch (IOException ex) {  
              ex.printStackTrace();  
              JSFUtil.enviarMenssagemErro("Erro ao realizar o Upload.");  
          }  
      }  
  }  



I would like your help.

Thanks

Erickfm8
Posts: 56
Joined: 22 Jun 2010, 14:25

05 Apr 2011, 19:41

Please some moderator of the forum could help me?
I'm three weeks with it.

Thanks

Erickfm8
Posts: 56
Joined: 22 Jun 2010, 14:25

05 Apr 2011, 22:09

..

Erickfm8
Posts: 56
Joined: 22 Jun 2010, 14:25

06 Apr 2011, 15:54

...

Erickfm8
Posts: 56
Joined: 22 Jun 2010, 14:25

08 Apr 2011, 18:51

Nobody?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests