Create sub report inside another sub using inputStream parameter

0

 

when I create this report using string parameter naoda error but when I use my custom reports coming from the database I get the bytes and step a inputStream of parsing when I have only one sub n of the error but when the 2 sub and each of those sub with another sub from the Error: Error loading object from InputStream.

 

generate report with two internal sub reports inside one another with inputStream data

http://uploaddeimagens.com.br/imagens/br-com-erp-web-estoque-controleent...

 

two or more of the error

net.sf.jasperreports.engine.JRException: Error loading object from InputStream.
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:282)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:262)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.loadReport(JRFillSubreport.java:396)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:375)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:437)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:351)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:281)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:504)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2026)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:752)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:279)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:123)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:558)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:122)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:648)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:970)
    at br.com.controlese.web.wicket.page.consultas.CriarRelatorioControleEntregaJasper.gerarRelatorioDeControleDeEntregas(CriarRelatorioControleEntregaJasper.java:218)
    at br.com.controlese.web.wicket.page.PainelAcaoModalControleEntrega$2.onClick(PainelAcaoModalControleEntrega.java:86)
    at org.apache.wicket.ajax.markup.html.AjaxLink$1.onEvent(AjaxLink.java:86)
    at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:146)
    at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:633)
    at sun.reflect.GeneratedMethodAccessor121.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
    at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
    at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:250)
    at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:236)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:890)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
    at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
    at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2298)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2767)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:798)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:298)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:57)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:277)
    ... 63 more

when I generate with parameter in string, I have satisfactory result in two or more deliveries in the report

but when I use the code to get the bytes of the report saved in the database

continuous using the JRBeanCollectionDataSource in the same way as the products

when you generate a report with only one entry of the right

but when there are 2 or more deliveries in the error report

http://uploaddeimagens.com.br/imagens/tibco_jaspersoft-_studio_2-png-4e2...

already tried to pass the JRBeanCollectionDataSource by parameter and dps use the JREmptyDataSource only but with one works but with two or more entries of the same error.

http://uploaddeimagens.com.br/imagens/tibco_jaspersoft-_studio-png

if anyone knows how to generate sub report inside another sub report using InputStream would appreciate

http://uploaddeimagens.com.br/imagens/br-com-erp-web-estoque-controleent...

http://uploaddeimagens.com.br/imagens/br-com-erp-web-estoque-controleent...

my cod

Search search = new Search(LayoutRelatorio.class);
        search.addFilterEqual("layout",LayoutRelatorio.LAYOUT_CONTROLE_ENTREGA);
        search.addFilterEqual("objetoEmpresas.empresa.id", controleEntrega.getSaidaEstoque().getEmpresa().getId());
        search.addFetch("anexoLayout");
 
        LayoutRelatorio layoutRelatorio = layoutRelatorioServico.searchUnique(search);
 
        String baseReportPath = "";
        InputStream is = null;
        JasperPrint jasperPrint = null;
 
        if(layoutRelatorio == null){
            params.put("entregas_path", Util.fileSeparator("controle_entrega/controle_entrega/entrega.jasper"));
            baseReportPath = Util.fileSeparator("controle_entrega/controle_entrega/controle_entrega.jasper");
            is = BasePage.class.getClassLoader().getResource(baseReportPath).openStream();
        }else{
            //inicia os paramentros como inputStream , (alterar para inpuStream no jasper principal)
            params.put("entregas_path", BasePage.class.getClassLoader().getResource("controle_entrega/controle_entrega/entrega.jasper").openStream());
            //relatorio personalizado com sub adicionados
            if(layoutRelatorio.getListaLayoutSubRelatorios()!=null && layoutRelatorio.getListaLayoutSubRelatorios().size() > 0){
                    //subLayouts
                        Search searchSub = new Search(LayoutSubRelatorio.class);
                        searchSub.addFetch("anexoLayout");
                        searchSub.addFilterEqual("layoutRelatorio.id", layoutRelatorio.getId());
 
                        List<LayoutSubRelatorio> layoutSubRelatorios = layoutRelatorioServico.searchSub(searchSub);
 
                        for(LayoutSubRelatorio layoutSub :layoutSubRelatorios){
                            // mudar o parament class do paramentro no jrxml de string  para java.io.InputStream
                            InputStream sub = new ByteArrayInputStream(layoutSub.getAnexoLayout().getBytes());
 
                                if(layoutSub.getLayout().equals(LayoutSubRelatorio.LAYOUT_CONTROLE_ENTREGA_SUB_PRODUTO)){
                                    params.put("entregas_path", sub);
                                }
                        }
                        is = new ByteArrayInputStream(layoutRelatorio.getAnexoLayout().getBytes());
            }else{
                // relatorio pai personalizados com sub padrao
                is = new ByteArrayInputStream(layoutRelatorio.getAnexoLayout().getBytes());
 
            }
        }
 
        try {
            if(entregasBeanList.isEmpty()){
                jasperPrint = JasperFillManager.fillReport(is, params, new JREmptyDataSource());
            }else{
                jasperPrint = JasperFillManager.fillReport(is, params, new JRBeanCollectionDataSource(entregasBeanList));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
 
 
....for (Entrega entrega : controleEntrega.getEntregas()) {
                entregasBeanList.add(new EntregaBean(entrega));
            }
....
public class EntregaBean implements Serializable{
        /**
         * 
         */
        private static final long serialVersionUID = 2444422503678630608L;
 
        private String numeroEntrega;
        private String situacao;
        private String dataPrevista;
        private String dataRealizada;
        private String tipoFrete;
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
 
        private List<EntregaProdutoBean> produtos = new ArrayList<>();
 
        public EntregaBean(Entrega entrega) {
            this.situacao = entrega.getSituacaoNome();
            this.dataPrevista = entrega.getDataPrevista() != null ? sdf.format(entrega.getDataPrevista()) : "";
            this.dataRealizada = entrega.getDataEntrega() != null ? sdf.format(entrega.getDataEntrega()): "";
            this.numeroEntrega = String.valueOf(entrega.getId());
 
            setTipoFrete(entrega.getTipoFreteNome());
 
            if (entrega.getEntregasProduto() != null && !entrega.getEntregasProduto().isEmpty()) {
                for (EntregaProduto entregaProduto : entrega.getEntregasProduto()) {
                    produtos.add(new EntregaProdutoBean(entregaProduto));
                }
            }
        }
 
        public JRDataSource getProdutos() {
            if(produtos != null && !produtos.isEmpty())
                return new JRBeanCollectionDataSource(produtos);
            return new JREmptyDataSource();
        }
 
}


guilhermehalo123's picture
Joined: Apr 28 2017 - 4:55am
Last seen: 2 months 5 days ago

0 Answers:

No answers yet
Feedback
randomness