Erro Primefaces + Lightbox

01/02/2016

3

Fala galera, boa tarde!

Estou com um problema de quebrar a cabeça aqui no trabalho, utilizando primefaces e lightbox.

Estou querendo exibir a imagem em miniatura em baixo da descrição, na tela pro cliente.

Entretanto, ta dando um erro de Scoped.

JSF
<p:dataTable
            id="tabelaAnexos"
            var="data"
            value="#{registroInformacaoManipularBean.form.anexoDtoList}"
            style="width:100%; margin-top:20px"
            emptyMessage="Não existem anexos para este registro">

        <p:column headerText="Anexo" >
            <h:outputText value="#{data.nome}"/>
        </p:column>

        <p:column headerText="Descrição" >
            <h:outputText value="#{data.descricao}"/>
            <p:lightBox styleClass="imagebox" id="lighbox1">
                <f:event type="preRenderComponent" listener="#{anexoInformacaoCRUDBean.iniciarArquivo(data)}"/>
                <h:outputLink  value="#{anexoInformacaoCRUDBean.imagem}">
                    <p:graphicImage value="#{anexoInformacaoCRUDBean.imagem}"/>
                </h:outputLink>
            </p:lightBox>
        </p:column>

        <p:column>
            <p:commandButton icon="fa fa-eye" title="Visualizar"
                           ajax="false" actionListener="#{anexoInformacaoCRUDBean.obterArquivo(data)}">
                <p:fileDownload value="#{anexoInformacaoCRUDBean.arquivo}" />
            </p:commandButton>

            <p:commandButton icon="fa fa-trash-o" title="Excluir" update=":tabelaAnexos" actionListener="#{anexoInformacaoCRUDBean.removerArquivo(data)}" rendered="#{not registroInformacaoManipularBean.isVisualizar()}" />

        </p:column>

    </p:dataTable>



Java
package br.com.petrobras.ticepes.swot.jsf.registroinformacao.anexoinformacao;


import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import br.com.petrobras.ticepes.swot.jsf.commons.BaseBean;
import br.com.petrobras.ticepes.swot.jsf.registroinformacao.RegistroInformacaoManipularBean;
import br.com.petrobras.ticepes.swot.usecase.anexoinformacao.dtos.AnexoInformacaoDto;
import org.omnifaces.cdi.ViewScoped;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;


@Named
@ViewScoped
public class AnexoInformacaoCRUDBean extends BaseBean {
    private String nomeArquivo;
    private String descricao;
    private AnexoInformacaoDto anexoTemp;

    @Inject
    private transient RegistroInformacaoManipularBean manipularBean;

    @Inject
    private transient AnexoInformacaoService anexoInformacaoService;

    //OBTER
    private StreamedContent arquivo;

    //LIGHTBOX VISUALIZAR
    private StreamedContent imagem;

    //INICIAR O ARQUIVODTO
    private AnexoInformacaoDto arquivoSolicitado;

    public void obterArquivo(AnexoInformacaoDto arquivoSolicitado) {
        this.arquivo = new DefaultStreamedContent(new ByteArrayInputStream(
                arquivoSolicitado.getArquivo()), "", arquivoSolicitado.getNome()
        );
    }

    public void iniciarArquivo(AnexoInformacaoDto arquivoSolicitado){
        this.arquivoSolicitado = arquivoSolicitado;
    }

    public void setImagem(StreamedContent imagem) {
        this.imagem = imagem;
    }


    public StreamedContent getImagem(){

        ByteArrayInputStream sdf = new ByteArrayInputStream(this.arquivoSolicitado.getArquivo());
        return new DefaultStreamedContent(sdf, "image/jpg", this.arquivoSolicitado.getNome());
}

    public void removerArquivo(AnexoInformacaoDto arquivoRemover) {
        this.manipularBean.getForm().getAnexoDtoList().remove(arquivoRemover);
    }

    public void onFileUpload(FileUploadEvent event) {
        if(event.getFile().getSize()  > 10000000){
            super.messages.globalError("Tamanho do anexo superior a 10MB");
        }else{
            anexoTemp = new AnexoInformacaoDto();
            nomeArquivo = event.getFile().getFileName();
            anexoTemp.setArquivo(event.getFile().getContents());
            anexoTemp.setNome(event.getFile().getFileName());
        }
    }

    public void enviarArquivo(){
        anexoTemp.setDescricao(this.descricao);
        if (this.manipularBean.getForm().getAnexoDtoList() == null){
            this.manipularBean.getForm().setAnexoDtoList(new ArrayList<AnexoInformacaoDto>());
        }
        this.manipularBean.getForm().getAnexoDtoList().add(anexoTemp);
        prepararProximoAnexo();
    }

    private void prepararProximoAnexo(){
        this.nomeArquivo = "";
        this.descricao ="";
        this.anexoTemp = null;
    }

    public boolean desabilitarUpload(){
        if(anexoTemp == null){
            return true;
        }else {
            return false;
        }
    }

    public String getNomeArquivo() {
        return nomeArquivo;
    }

    public void setNomeArquivo(String nomeArquivo) {
        this.nomeArquivo = nomeArquivo;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public StreamedContent getArquivo() {
        return arquivo;
    }

    public void setArquivo(StreamedContent arquivo) {
        this.arquivo = arquivo;
    }

}



Erro

19:19:27,265 SEVERE [org.primefaces.application.resource.StreamedContentHandler] (http-/127.0.0.1:8080-79) Error in streaming dynamic resource. org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type org.omnifaces.cdi.ViewScoped
19:19:27,265 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/swot-web].[Faces Servlet]] (http-/127.0.0.1:8080-79) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: java.io.IOException: javax.el.ELException: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type org.omnifaces.cdi.ViewScoped
	at org.primefaces.application.resource.StreamedContentHandler.handle(StreamedContentHandler.java:94) [primefaces-5.2.jar:5.2]
	at org.primefaces.application.resource.PrimeResourceHandler.handleResourceRequest(PrimeResourceHandler.java:72) [primefaces-5.2.jar:5.2]
	at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1]
	at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1]
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100) [primefaces-5.2.jar:5.2]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.omnifaces.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:122) [omnifaces-2.1.jar:2.1]
	at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108) [omnifaces-2.1.jar:2.1]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:420) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
	at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
	at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:355) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:911) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.tomcat.util.net.NioEndpoint$ChannelProcessor.run(NioEndpoint.java:936) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]
	at org.apache.tomcat.util.net.NioEndpoint$DefaultThreadFactory$1$1.run(NioEndpoint.java:1249) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]
Caused by: javax.el.ELException: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type org.omnifaces.cdi.ViewScoped
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:309) [jboss-el-api_2.2_spec-1.0.4.Final-redhat-1.jar:1.0.4.Final-redhat-1]
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.28.redhat-8.jar:2.1.28.redhat-8]
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.28.redhat-8.jar:2.1.28.redhat-8]
	at org.apache.el.parser.AstValue.getValue(AstValue.java:166) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-1.1.28.Final-redhat-1.jar:1.1.28.Final-redhat-1]
	at org.primefaces.application.resource.StreamedContentHandler.handle(StreamedContentHandler.java:58) [primefaces-5.2.jar:5.2]
	... 30 more
Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type org.omnifaces.cdi.ViewScoped
	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608) [weld-core-1.1.28.Final-redhat-1.jar:1.1.28.Final-redhat-1]
	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71) [weld-core-1.1.28.Final-redhat-1.jar:1.1.28.Final-redhat-1]
	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core-1.1.28.Final-redhat-1.jar:1.1.28.Final-redhat-1]
	at br.com.petrobras.ticepes.swot.jsf.registroinformacao.anexoinformacao.AnexoInformacaoCRUDBean$Proxy$_$$_WeldClientProxy.getImagem(AnexoInformacaoCRUDBean$Proxy$_$$_WeldClientProxy.java) [classes:]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_60]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_60]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_60]
	at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_60]
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:304) [jboss-el-api_2.2_spec-1.0.4.Final-redhat-1.jar:1.0.4.Final-redhat-1]
	... 36 more




Então, resumindo. Eu pego a imagem em byte, transformo utilizando o DefaultStreamedContent.
Dá erro de Scoped. Outra observação é que o botão de download que criei funciona perfeitamente.
Responder