I'm new to jasper reports and I'm trying to populate a single report with two different java beans, my report has two different sections one for the patient info and the other for the medications, I created two different beans one for the medication and the other for the patient info and from my beanFactory
class I have two methods returning a list of beans for each bean.
I'm getting java.lang.NoSuchMethodException: Unknown property 'med' on class 'class jasperreport.Bean'
this is the code that compiles and fills the jasper report:
public class or {
public or(){
try {
InputStream stream= new FileInputStream("ordonanceReport.jrxml");
JasperReport MasterReport = JasperCompileManager.compileReport(stream);
Map<String, Object> parameters = new HashMap();
parameters.put("ReportDataSource", new JRBeanCollectionDataSource(BeanFactory.getMedBeans()));
JasperPrint print= JasperFillManager.fillReport(MasterReport, parameters
,new JRBeanCollectionDataSource(BeanFactory.getInfoBeans()));
JasperViewer.viewReport(print);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
or o= new or();
}
}
these are my two beans: medBean
public class medBean {
private String med="";
public medBean(String med) {
super();
this.med = med;
}
public String getMed() {
return med;
}
public void setMed(String med) {
this.med = med;
}
}
InfoBean
public class InfoBean {
private String date="";
private String nomPatient="";
private String prenomPatient="";
private String agePatient="";
public InfoBean(String date, String nomPatient, String prenomPatient, String agePatient) {
super();
this.date = date;
this.nomPatient = nomPatient;
this.prenomPatient = prenomPatient;
this.agePatient = agePatient;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getNomPatient() {
return nomPatient;
}
public void setNomPatient(String nomPatient) {
this.nomPatient = nomPatient;
}
public String getPrenomPatient() {
return prenomPatient;
}
public void setPrenomPatient(String prenomPatient) {
this.prenomPatient = prenomPatient;
}
public String getAgePatient() {
return agePatient;
}
public void setAgePatient(String agePatient) {
this.agePatient = agePatient;
}
}
this is the bean factory class: BeanFactory
public class BeanFactory {
public static Collection getInfoBeans(){
List<Bean> allbeans = new ArrayList<>();
try {
allbeans.add(new Bean("12/01","gherbi","mohamed","22"));
allbeans.add(new Bean("13/33","gherbi","Hicham","27"));
}
catch(Exception e){
e.printStackTrace();
}
return allbeans;
}
public static Collection getMedBeans(){
List<medBean> allbeans = new ArrayList<>();
try {
allbeans.add(new medBean("12/0dgddghd"));
allbeans.add(new medBean("13/3bdhhsdhd"));
}
catch(Exception e){
e.printStackTrace();
}
return allbeans;
}
}
I have added this line to my jasperreport file to be able to get the medBean:
<parameter name="ReportDataSource" class="net.sf.jasperreports.engine.JRDataSource"/>
and this is my Jasper report .jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2017-01-18T17:16:19 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ordonanceReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6e17b895-f9d9-42b5-830b-1ef42a6369b6">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="ReportDataSource" class="net.sf.jasperreports.engine.JRDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="date" class="java.lang.String"/>
<field name="nomPatient" class="java.lang.String"/>
<field name="prenomPatient" class="java.lang.String"/>
<field name="agePatient" class="java.lang.String"/>
<field name="med" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="139" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="195" height="30" uuid="6f3a4542-cf3d-4098-9470-b37aef5efdfd"/>
<textElement textAlignment="Right">
<font size="22" isBold="true"/>
</textElement>
<text><![CDATA[الحكيم: عابد محمد الامين]]></text>
</staticText>
<staticText>
<reportElement x="10" y="30" width="200" height="20" forecolor="#020108" uuid="fcf14a3e-c799-48e7-865e-3e372d1429e6">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Serif" size="14" isBold="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Dr.ABBED Mohamed El Amine]]></text>
</staticText>
<staticText>
<reportElement x="35" y="50" width="145" height="20" uuid="0a058164-8f16-479f-acfa-5f1d4b086420"/>
<textElement>
<font fontName="DejaVu Serif" size="14" isItalic="true"/>
</textElement>
<text><![CDATA[Chirurgien Dentiste]]></text>
</staticText>
<staticText>
<reportElement x="20" y="80" width="125" height="20" uuid="2cc59804-45cc-4c88-851d-eb79974be02f"/>
<textElement textAlignment="Justified"/>
<text><![CDATA[N° 14 Route Nationale N° 04]]></text>
</staticText>
<staticText>
<reportElement x="30" y="100" width="108" height="20" uuid="091aea38-23a0-48ac-b40b-18044cf46650"/>
<text><![CDATA[Oued Fodda- CHLEF]]></text>
</staticText>
<staticText>
<reportElement x="38" y="120" width="100" height="18" uuid="f571acb4-2413-47c1-835c-16f09fd29023"/>
<text><![CDATA[Tel : 027 44 79 03]]></text>
</staticText>
<staticText>
<reportElement x="320" y="10" width="90" height="20" uuid="bfeaf387-ba74-4e31-ad47-ef288e9f5620"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[Oued-Fodda, le ]]></text>
</staticText>
<textField>
<reportElement x="420" y="10" width="140" height="20" uuid="aa3c34c4-f7e7-4650-b351-05d305ba9331"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<rectangle>
<reportElement x="310" y="52" width="250" height="78" uuid="91636d06-0155-4a81-85f9-21e53571fccf"/>
</rectangle>
<staticText>
<reportElement x="320" y="59" width="63" height="20" uuid="cfc38414-4030-402a-8782-7ebf95b7cb3d"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[Nom :]]></text>
</staticText>
<staticText>
<reportElement x="320" y="80" width="63" height="20" uuid="2c1f37f0-67c9-4bbd-b0ed-7e4214445cea"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[Prenom :]]></text>
</staticText>
<staticText>
<reportElement x="320" y="100" width="63" height="22" uuid="7564b34c-0c52-4b96-94f8-0e5b3fd1c7ab"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[Age :]]></text>
</staticText>
<textField>
<reportElement x="390" y="59" width="130" height="21" uuid="12d4fae4-732d-46b9-856f-b4aab950b34c"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{nomPatient}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="390" y="80" width="130" height="24" uuid="24b7cbaa-4fab-497f-90fa-1476d48acd09"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{prenomPatient}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="390" y="104" width="130" height="18" uuid="f645445e-baf2-445d-b646-bbc58b433358"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{agePatient}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="50" splitType="Stretch">
<staticText>
<reportElement x="180" y="6" width="140" height="44" uuid="47e85cd8-03fa-414b-ae1d-448df4222196"/>
<textElement>
<font fontName="Serif" size="26" isItalic="true"/>
</textElement>
<text><![CDATA[Ordonnance]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="44" splitType="Stretch">
<staticText>
<reportElement x="36" y="0" width="100" height="30" uuid="26073bf7-15a6-43e9-9b4e-4bd01b5ec2f6"/>
<text><![CDATA[med]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="214" splitType="Stretch">
<textField>
<reportElement x="0" y="10" width="544" height="30" uuid="6cc37921-6390-4c94-9ecd-f4c8e85432b0"/>
<textFieldExpression><![CDATA[$F{med}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="5" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="13" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
I feel like there is something wrong with my assumptions here does it work this way or do I need change to something? PS: I don't want to use a subreport, I know that that's a possibility, I want to use a single report that contains everything.