component <p:graphicImage value="#{foto.image}"/> not show

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

25 Mar 2011, 20:49

Personnel component <p:graphicImage value="#{foto.image}"/> not show the image anyone know what might be


.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 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="somCliente, itxDescricao, clkGravar, 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="somCliente, itxDescricao, clkGravar, 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: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="foto"
                                value="#{albumMB.fotos}"
                                columns="2"
                                rows="1"
                                paginator="true"
                                style="width:30%">
                        <p:column>
                            <p:panel header="#{foto.nome}"
                                     style="text-align:center">
                                <h:panelGrid columns="1"
                                             style="width:100%">
                                    <p:graphicImage value="#{foto.imagem}"/>
                                </h:panelGrid>
                            </p:panel>
                        </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 , dtfot"
                                      style="margin-right:20px"/>
                        <p:commandLink  id="clkGravar"
                                        title="Gravar"
                                        action="#{albumMB.gravar}"
                                        disabled="#{!empty albumMB.album.id}"
                                        style="margin-right:20px"
                                        update="somCliente, itxDescricao, frmGridAlbum">
                            <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="somCliente, itxDescricao, frmGridAlbum"
                                       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

   public void selecionarFoto(FileUploadEvent event) {
        System.out.println("okkk");
        UploadedFile uf = event.getFile();
        String nomeArquivo = uf.getFileName();
        InputStream is = null;
        Foto foto = new Foto();
        try {
            is = uf.getInputstream();
            byte[] b = new byte[is.available()];
            foto.setNome(nomeArquivo);
            foto.setFoto(b);
            //InputStream stream = new ByteArrayInputStream(b);
            //foto.setImagem(new DefaultStreamedContent(stream));

           foto.setImagem(new DefaultStreamedContent(event.getFile().getInputstream()));
            fotos.add(foto);
            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.");
            }
        }
    }


Some know what can be?

Therefore I thank you

lazaronixon
Posts: 172
Joined: 05 Jan 2011, 22:02

25 Mar 2011, 23:20

I am brazilian too but i will speak in english...

You need to use a @sessionscoped in your Managed bean otherwise graphicimage does'nt work...
I open a inssue about it but nothing was done until now..

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

28 Mar 2011, 15:21

I was using "ViewScoped" SessionScoped moved, but the picture still does not appear.

Have you tried, nothing works.

Thanks

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

28 Mar 2011, 18:55

...

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

31 Mar 2011, 21:04

Help ??

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests