0
I am using a Composite to print out reports Note: I can send the report with my City usually the problem is with the material.
Menu Impressão Composite
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:sec="http://www.springframework.org/security/facelets/tags"
xmlns:util="http://java.sun.com/jsf/composite/componentes"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui">
<composite:interface>
<composite:attribute name="bean" required="true"/>
</composite:interface>
<composite:implementation>
<h:commandLink immediate="true">
<f:setPropertyActionListener value="1" target="#{cc.attrs.bean.tipoRelatorio}"/>
<p:fileDownload value="#{cc.attrs.bean.arquivoReport}"/>
<h:graphicImage library="img" name="pdf.png"/>
</h:commandLink>
<h:commandLink immediate="true">
<f:setPropertyActionListener value="2" target="#{cc.attrs.bean.tipoRelatorio}"/>
<p:fileDownload value="#{cc.attrs.bean.arquivoReport}"/>
<h:graphicImage library="img" name="excel.png"/>
</h:commandLink>
<h:commandLink immediate="true">
<f:setPropertyActionListener value="3" target="#{cc.attrs.bean.tipoRelatorio}"/>
<p:fileDownload value="#{cc.attrs.bean.arquivoReport}"/>
<h:graphicImage library="img" name="html.png"/>
</h:commandLink>
<h:commandLink immediate="true">
<f:setPropertyActionListener value="4" target="#{cc.attrs.bean.tipoRelatorio}"/>
<p:fileDownload value="#{cc.attrs.bean.arquivoReport}"/>
<h:graphicImage library="img" name="ods.png"/>
</h:commandLink>
</composite:implementation>
</html>
Cadastro de Material
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:sec="http://www.springframework.org/security/facelets/tags"
xmlns:util="http://java.sun.com/jsf/composite/componentes"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/templates/templatePrincipal.xhtml" >
<ui:define name="corpo">
<!-- Cadastro de MATERIAL FORM -->
<h:form id="formCadastro" prependId="false">
<c:set var="isCadastro" value="true" scope="view" />
<br/>
<p:panel header="Cadastro de Material" id="panelCadastro" styleClass="tamanhoDosPanels">
<h:panelGrid id="gridCidade" columns="3">
<!-- Label Código -->
<h:outputLabel for="id" value="Código: " id="labelId" />
<!-- Input Código -->
<p:inputText id="id" styleClass="estiloIdCadastro" disabled="true"
value="#{materialBeanView.objetoSelecionado.idMaterial}" />
<!-- Alinhamento um 3º Campo -->
<h:outputLabel />
<!-- Label Nome da Material -->
<h:outputLabel id="labelNomeConsultaMaterial" for="materialNome"
value="Nome * :" />
<!-- Input Nome da Material -->
<p:inputText id="materialNome" styleClass="estiloInputNome"
required="true" maxlength="100"
value="#{materialBeanView.objetoSelecionado.nomeMaterial}"
requiredMessage="Informe o nome do material" />
<!-- Redirecionar Mensagem do Erro -->
<p:message for="materialNome" id="materialNomeMessageError" />
<!-- Label Quantidade -->
<h:outputLabel for="quantidadeMaterial" id="labelQuantidadeMaterial" value="Quantidade * :" />
<p:inputText id="quantidadeMaterial" rendered="true"
requiredMessage="Informe a quantidade do material"
value="#{materialBeanView.objetoSelecionado.quantidade}"/>
<!-- Redirecionar Mensagem do Erro -->
<p:message for="quantidadeMaterial" id="materialQuantidadeMessageError" />
<!-- Label Valor Unitario -->
<h:outputLabel for="valorUnitario" id="labelValorUnitario" value="Valor Unitário * :" />
<p:inputText id="valorUnitario" rendered="true"
requiredMessage="Informe a valor do material"
value="#{materialBeanView.objetoSelecionado.valorUnitario}"/>
<!-- Redirecionar Mensagem do Erro -->
<p:message for="valorUnitario" id="materialValorUnitarioMessageError" />
</h:panelGrid>
</p:panel>
<div class="espacoBranco" />
<!-- Chama Botões Recarrega Template growl messages e tabela de resultados-->
<util:botoesCrud
managedBeanView="#{materialBeanView}"
camposReload=":formTemplate:msg, tableResult"
botaoNovo="#{contextoBean.possuiAcesso('CIDADE_NOVO', 'ADMIN')}"
botaoSalvar="#{contextoBean.possuiAcesso('CIDADE_NOVO', 'ADMIN')
and materialBeanView.objetoSelecionado.idMaterial == null}"
botaoAtualizar ="#{contextoBean.possuiAcesso('ACESSO_EDITAR', 'ADMIN')
and materialBeanView.objetoSelecionado.idMaterial != null}"
botaoRedirecionar ="#{contextoBean.possuiAcesso('ACESSO_EDITAR', 'ADMIN')}"
>
</util:botoesCrud>
</h:form>
<!-- JavaScript de Foco no Nome da Cidade e Configuração do Enter -->
<script type="text/javascript" charset="UTF-8">
addFocoCampo("materialNome");
gerenciaTeclaEnter();
</script>
<!-- Espaço entre FORM e LISTA -->
<div class="espacoBranco"/>
<p:panel styleClass="tamanhoDosPanels">
<!-- Lista de Material DataTable -->
<p:dataTable id="tableResult" value="#{materialBeanView.list.list}" style="background-color: #d7e7f9; border: none;border-style: hidden"
var="objeto" emptyMessage="Não existem valores para exibição"
rows="20" paginator="true" paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink}
{PreviousPageLink} {PageLinks}
{NextPageLink} {LastPageLink}
{RowsPerPageDropdown} ">
<ui:include src="/resources/componentes/colunasDataTableMaterial.xhtml"/>
</p:dataTable>
</p:panel>
</ui:define>
</ui:composition>
</html>
ADVERTÊNCIA: /resources/componentes/menuImpressao.xhtml @20,60 value="#{cc.attrs.bean.arquivoReport}": Error reading 'arquivoReport' on type br.com.projeto.bean.view.MaterialBeanView javax.el.ELException: /resources/componentes/menuImpressao.xhtml @20,60
value="#{cc.attrs.bean.arquivoReport}": Error reading 'arquivoReport' on type br.com.projeto.bean.view.MaterialBeanView at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114) at org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:53)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813) at javax.faces.component.UICommand.broadcast(UICommand.java:300) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931) at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at br.com.projeto.filter.FilterOpenSessionInView.doFilter(FilterOpenSessionInView.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: javax.el.ELException: Error reading
'arquivoReport' on type br.com.projeto.bean.view.MaterialBeanView at javax.el.BeanELResolver.getValue(BeanELResolver.java:110) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116) at com.sun.el.parser.AstValue.getValue(AstValue.java:163) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219) at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:158)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) ... 71 more Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585) at java.lang.Class.getConstructor0(Class.java:2885) at java.lang.Class.getConstructor(Class.java:1723) at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:814)
at net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(JasperCompileManager.java:377) at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:462) at net.sf.jasperreports.engine.fill.JRBaseFiller.
<init>(JRBaseFiller.java:405) at net.sf.jasperreports.engine.fill.JRVerticalFiller.
<init>(JRVerticalFiller.java:89) at net.sf.jasperreports.engine.fill.JRVerticalFiller.
<init>(JRVerticalFiller.java:104) at net.sf.jasperreports.engine.fill.JRVerticalFiller.
<init>(JRVerticalFiller.java:62) at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179) at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:108) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:668)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:984) at br.com.projeto.report.util.ReportUtil.geraRelatorio(ReportUtil.java:115) at br.com.projeto.report.util.BeanReportView.getArquivoReport(BeanReportView.java:44)
at br.com.projeto.bean.view.MaterialBeanView.getArquivoReport(MaterialBeanView.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at javax.el.BeanELResolver.getValue(BeanELResolver.java:99) ... 78 more Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701) ... 101 more
Minha Model
package br.com.projeto.model.classes;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.envers.Audited;
import br.com.projeto.anotacoes.IdentificaCampoPesquisa;
@Entity
@Audited
@Table(name = "material")
@SequenceGenerator(name = "material_seq", sequenceName = "material_seq", initialValue = 1, allocationSize = 1)
public class Material implements Serializable {
private static final long serialVersionUID = 1 L;
@IdentificaCampoPesquisa(descricaoCampo = "Código", campoConsulta = "idMaterial", principal = 1)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "material_seq")
private Long idMaterial;
@IdentificaCampoPesquisa(descricaoCampo = "Nome", campoConsulta = "nomeMaterial", principal = 2)
private String nomeMaterial;
private int quantidade;
private Double valorUnitario;
@Version
@Column(name = "versionNum")
private int versionNum;
//EQUALS E HASCODE
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((idMaterial == null) ? 0 : idMaterial.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Material other = (Material) obj;
if (idMaterial == null) {
if (other.idMaterial != null)
return false;
} else if (!idMaterial.equals(other.idMaterial))
return false;
return true;
}
//GETTERS E SETTERS
public Long getIdMaterial() {
return idMaterial;
}
public void setIdMaterial(Long idMaterial) {
this.idMaterial = idMaterial;
}
public String getNomeMaterial() {
return nomeMaterial;
}
public void setNomeMaterial(String nomeMaterial) {
this.nomeMaterial = nomeMaterial;
}
public int getQuantidade() {
return quantidade;
}
public void setQuantidade(int quantidade) {
this.quantidade = quantidade;
}
public Double getValorUnitario() {
return valorUnitario;
}
public void setValorUnitario(Double valorUnitario) {
this.valorUnitario = valorUnitario;
}
public int getVersionNum() {
return versionNum;
}
public void setVersionNum(int versionNum) {
this.versionNum = versionNum;
}
@Override
public String toString() {
return "Material [idMaterial=" + idMaterial + ", nomeMaterial=" + nomeMaterial + ", quantidade=" + quantidade +
", valorUnitario=" + valorUnitario + "]";
}
}
Meu ManagedBean
package br.com.projeto.bean.view;
import javax.faces.bean.ManagedBean;
import org.primefaces.model.StreamedContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import br.com.framework.inteface.crud.InterfaceCrud;
import br.com.projeto.bean.geral.BeanManagedViewAbstract;
import br.com.projeto.carregamento.lazy.CarregamentoLazyListForObjeto;
import br.com.projeto.geral.controller.MaterialController;
import br.com.projeto.model.classes.Material;
@Controller
@Scope(value = "session")
@ManagedBean(name = "materialBeanView")
public class MaterialBeanView extends BeanManagedViewAbstract {
private static final long serialVersionUID = 1L;
private Material objetoSelecionado = new Material();
private String url = "/cadastro/cad_material.jsf?faces-redirect=true";
private String urlFind = "/cadastro/find_material.jsf?faces-redirect=true";
private CarregamentoLazyListForObjeto<Material> list = new CarregamentoLazyListForObjeto<Material>();
@Autowired
private MaterialController materialController;
/**
* Metodos Getter E Setters dos objetos
* @return
*/
@Override
public StreamedContent getArquivoReport() throws Exception {
super.setNomeRelatorioJasper("report_material");
super.setNomeRelatorioSaida("report_material");
super.setListDataBeanCollectionReport(materialController.findList(getClassImp()));
return super.getArquivoReport();
}
public Material getObjetoSelecionado() {
return objetoSelecionado;
}
public void setObjetoSelecionado(Material objetoSelecionado) {
this.objetoSelecionado = objetoSelecionado;
}
public String getUrl() {
return url;
}
public String getUrlFind() {
return urlFind;
}
public void setUrlFind(String urlFind) {
this.urlFind = urlFind;
}
public CarregamentoLazyListForObjeto<Material> getList() throws Exception {
return list;
}
/**
* Metodos para manipular salvamento, exclusões, editar, novo
*/
@Override
public String save() throws Exception {
objetoSelecionado = materialController.merge(objetoSelecionado);
return "";
}
@Override
public void saveNotReturn() throws Exception {
list.clean();
objetoSelecionado = materialController.merge(objetoSelecionado);
list.add(objetoSelecionado);
objetoSelecionado = new Material();
sucesso();
}
@Override
public void saveEdit() throws Exception {
saveNotReturn();
}
@Override
public String novo() throws Exception {
setarVariaveisNulas();
return getUrl();
}
@Override
public void setarVariaveisNulas() throws Exception {
list.clean();
objetoSelecionado = new Material();
}
@Override
public String editar() throws Exception {
list.clean();
return getUrl();
}
@Override
public void excluir() throws Exception {
objetoSelecionado = (Material) materialController.getSession().get(getClassImp(), objetoSelecionado.getIdMaterial());
materialController.delete(objetoSelecionado);
list.remove(objetoSelecionado);
objetoSelecionado = new Material();
sucesso();
}
@Override
protected Class<Material> getClassImp() {
return Material.class;
}
@Override
public String redirecionarFindEntidade() throws Exception {
setarVariaveisNulas();
return urlFind;
}
@Override
protected InterfaceCrud<Material> getController() {
return materialController;
}
@Override
public void consultarEntidade() throws Exception {
objetoSelecionado = new Material();
list.clean();
list.setTotalRegistroConsulta(super.totalRegistroConsulta(), super.getSqlLazyQuery());
}
@Override
public String condicaoAndParaPesquisa() throws Exception {
return "";
}
}