java - Unable to retrieve value from a JavaBean while generating reports using JasperReports API -
i trying generate simple jr report list.
i keep getting error retrieving field value bean : name
this error comes due wrong getter method-name since jasper uses reflection take fields bean. after correcting getter method-name. keep getting exception. there other problem?
my jrxml file is
<?xml version="1.0" encoding="utf-8" ?> <!doctype jasperreport public "//jasperreports//dtd report design//en" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperreport name="simplereport"> <field name="name" class="java.lang.string"/> <field name="count" class="java.lang.string"/> <title> <band height="50"> <statictext> <reportelement x="0" y="0" width="180" height="15"/> <textelement/> <text><![cdata[report]]></text> </statictext> </band> </title> <pageheader> <band/> </pageheader> <columnheader> <band height="20"> <statictext> <reportelement x="180" y="0" width="180" height="20"/> <textelement> <font isunderline="true"/> </textelement> <text><![cdata[event name]]></text> </statictext> <statictext> <reportelement x="360" y="0" width="180" height="20"/> <textelement> <font isunderline="true"/> </textelement> <text><![cdata[count]]></text> </statictext> </band> </columnheader> <detail> <band height="20"> <textfield> <reportelement x="180" y="0" width="180" height="15"/> <textelement/> <textfieldexpression><![cdata[$f{name}]]></textfieldexpression> </textfield> <textfield> <reportelement x="360" y="0" width="180" height="15"/> <textelement/> <textfieldexpression><![cdata[$f{count}]]></textfieldexpression> </textfield> </band> </detail> <columnfooter> <band/> </columnfooter> <pagefooter> <band height="15"> <statictext> <reportelement x="0" y="0" width="40" height="15"/> <textelement/> <text><![cdata[page:]]></text> </statictext> <textfield> <reportelement x="40" y="0" width="100" height="15"/> <textelement/> <textfieldexpression class="java.lang.integer"><![cdata[$v{page_number}]]></textfieldexpression> </textfield> </band> </pagefooter> <summary> <band/> </summary> </jasperreport>
bean class
class eventbean { private string name; private string count; public string getname() { return name; } public void setname(string name) { this.name = name; } public string getcount() { return count; } public void setcount(string count) { this.count = count; } } class eventnamelist { public arraylist<eventbean> getdatabeanlist() { arraylist<eventbean> list = new arraylist<eventbean>(); list.add(generate("flow", "100")); list.add(generate("non flow", "300")); list.add(generate("allow", "600")); list.add(generate("deny", "50")); return list; } private eventbean generate(string name, string country) { eventbean bean = new eventbean(); bean.setname(name); bean.setcount(country); return bean; } }
and generating reports here
jaspercompilemanager.compilereporttofile(inpuutjrxml, outputjasper); eventnamelist list = new eventnamelist(); jrbeancollectiondatasource beanlist = new jrbeancollectiondatasource(list.getdatabeanlist()); jasperprint jasperprint = jasperfillmanager.fillreport(outputjasper, new hashmap(), beanlist); jasperexportmanager.exportreporttopdfstream(jasperprint, new fileoutputstream(pefoutput));
do need make more modification bean class?
the solution simple - should change access modifier of javabean class public.
like this:
public class eventbean { private string name; private string count; public string getname() { return name; } public void setname(string name) { this.name = name; } public string getcount() { return count; } public void setcount(string count) { this.count = count; } }
don't forget using own package.
you can find more information javabean data sources here
Comments
Post a Comment