2
I’ve been looking for three days now and I can’t solve this problem. Let’s get the explanation: I’m creating a report in Jaspersoft studio and linking with my database, in the preview of my report (inside Jaspersoft software) everything is working perfectly. As can be seen in the following images:
I have only 3 Fields in my report: name, measure and neighborhood.
Inside my software, when I call the report it’s two different mistakes, I can’t figure out what to do.
Follow my sources for better viewing:
Reporterioutils - Class that will generate the report
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();
}
}
My Managed 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);
}
}
This is the mistake it generates
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123) at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96) at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:109) at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.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.jasperreports.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) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:892) at net.sf.jasperreports.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.medidas.utils.RelatorioUtil.executarRelatorio(RelatorioUtil.java:57) at br.com.agilles.medidas.beans.MBRelatorio.emitir(MBRelatorio.java:58) Caused by: java.lang.NoSuchMethodException: Unknown property '' on class 'class br.com.agilles.medidas.models.Relatorio' at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1277) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:808) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884) at org.apache.commons.beanutils.PropertyUtils.getProperty(Propertyutils.java:464) at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(Jrabstractbeandatasource.java:111) ... 57 more
Important to say: My Jrbeancollectiondatasource is coming completely filled with all the right data: name, measure and neighborhood.
Someone can help me?
java.lang.NoSuchMethodException: Unknown property '' on class 'class br.com.agilles.medidas.models.Relatorio'
&#It seems that here, he is trying to find a variable with empty field declaration, and finds no variable declared as "". I’ve never worked much with JR, but try to see if your Data source contains the Fields you need popular, with the correct names.– Gustavo Cinque
Yes, it seems that he tries to access by reflection within the Report class an unnamed field.
– Gustavo Cinque
my data source is coming with the same fields as the report. It comes with an array of size 3 that is coming from the database. Each object is populated with the field name, measure and neighborhood.
– Jilles Ragonha
I get it, @Jilles. Please check if there is no wrong value inside the file
.jrxml
, and also, if possible, edit the question and put the classRelatorio
.– Gustavo Cinque