我正在创建关于 Jaspersoft Studio 的报告,预览一切正常。
我的报告中只有3个字段:nome,medida e bairro。
在我的应用程序中,当我尝试生成报告时它会给出错误
我的源代码:
Class RelatorioUtils
public static void executarRelatorio(String caminhoRelatorio, Map<String, Object> parametros, String nomeRelatorio, JRBeanCollectionDataSource fonteDados) throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
//pegar caminho do relatorio jasper
InputStream reportStream = context.getExternalContext().getResourceAsStream(caminhoRelatorio);
response.setContentType("application/pdf");
try {
ServletOutputStream servletOutput = null;
try {
servletOutput = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
if (parametros == null) {
parametros = new HashMap<String, Object>();
}
JasperRunManager.runReportToPdfStream(reportStream, servletOutput, parametros, fonteDados);
try {
servletOutput.flush();
servletOutput.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (JRException e) {
e.printStackTrace();
} finally {
context.getResponseComplete();
}
}
我的托管Bean
public void emitir() {
relatorios = dao.listarTodos();
JRBeanCollectionDataSource fonteDados = new JRBeanCollectionDataSource(relatorios); // aqui está vindo completo meu JRbeanCollection está trazendo todos os dados que preciso
FacesContext context = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
try {
RelatorioUtil.executarRelatorio("/relatorios/RelatorioMedidaCautelar.jasper", null, "Relatorio", fonteDados);
} catch (IOException ex) {
Logger.getLogger(MBRelatorio.class.getName()).log(Level.SEVERE, null, ex);
}
}
我的豆子
enpublic class MedidaRelatorio {
private String nome;
private String bairro;
private String medida;
public MedidaRelatorio() {
}
public MedidaRelatorio(String nome, String bairro, String medida) {
this.nome = nome;
this.bairro = bairro;
this.medida = medida;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getMedida() {
return medida;
}
public void setMedida(String medida) {
this.medida = medida;
}
}
错误:
net.sf.jasperreports.engine.JRException:从bean检索字段值时出错:在net.sf.jasperreports.engine处的net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)。在net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset。)的net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:109)中的data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)。 java:1358)at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1259)at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1235)at net.sf .sasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1614)at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:150)at net.sf.jasperreports.engine.fill.JRBaseFiller .fill(JRBaseFiller.java:963)net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:892)at net.sf .sasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:668)at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager) .java:649)at net.sf.jasperreports.engine.JasperRunManager.runToPdfStream(JasperRunManager.java:437)at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfStream(JasperRunManager.java:858)at br.com.agilles。在br.com.agilles.medidas.beans.MBRelatorio.emitir(MBRelatorio.java:58)的medidas.utils.RelatorioUtil.executarRelatorio(RelatorioUtil.java:57)引起:java.lang.NoSuchMethodException:类上的未知属性''位于org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java)的org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1277)的'class br.com.agilles.medidas.models.Relatorio' 808)在org.apache.commons.bean中的org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884) tils.PropertyUtils.getProperty(PropertyUtils.java:464)at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)... 57 more
任何人都可以帮助我吗?