Jump to content

Passing for data In JRBeanCollectionDataSource using php issue


jazebmazher728

Recommended Posts

Hi,

I am facing this issue when i am passing JRBeanCollectionDataSource using php/java bridge then i am see this error:

Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:JasperFillManager]]->fillReport((o:JasperReport)[o:JasperReport], (i:Map)[o:HashMap], (i:JRDataSource)[o:JRBeanCollectionDataSource]). Cause: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $F{debit} VM: 1.8.0_211@http://java.oracle.com/" at: #-26 net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:782) #-25 net.sf.jasperreports.components.table.fill.FillTableSubreport.prepareSubreport(FillTableSubreport.java:156) #-24 net.sf.jasperreports.components.table.fill.FillTable.prepare(FillTable.java:392) #-23 net.sf.jasperreports.engine.fill.JRFillComponentElement.prepare(JRFillComponentElement.java:151) #-22 net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331) #-21 net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:384) #-20 net.sf.jasperreports.engine.fil in http://localhost:8080/JavaBridgeTemplate721/java/Java.inc on line 223

 

here is my php code

<?php

require_once("http://localhost:8080/JavaBridgeTemplate721/java/Java.inc");

try {

    $jasperxml = new java("net.sf.jasperreports.engine.xml.JRXmlLoader");
    $jasperDesign = $jasperxml->load(realpath("customer.jrxml"));
    $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
    $report = $compileManager->compileReport($jasperDesign);
} catch (JavaException $ex) {
    echo $ex;
}

$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
$array1 = ['debit'=>['20.00','30.00']];
$array2 = ['debit'=>['20.00','30.00']];
$array3 = '5.00';
$array4 = '2000.00';
$array5 = '11120.00';
$array6 = '5562.00)';
//$arrays = ['20.00','30.00','40.00'];
$params = new Java("java.util.HashMap");
/*
$params->put("debit", "30.00");
$params->put("credit", "3.00");
$params->put("description", "Test123Customer");
$params->put("date", "2019-07-22 06:37:09");
*/
$arrayList = new java( 'java.util.ArrayList' );
$arrayList->add($array1);
$arrayList->add($array2);
$class = new JavaClass("java.lang.Class");
$beanCollection = new Java("net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" , $arrayList);
$params->put('DataSource', $beanCollection);
$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");
$jasperPrint = $fillManager->fillReport($report, $params, $beanCollection);
$exporter = new java("net.sf.jasperreports.engine.JRExporter");

switch ($_POST['format']) {
    case 'pdf':
        $outputPath = realpath(".")."/"."output.pdf";
        
        $exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
        $exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
        break;
}
?>

 

and here is my jrxml code 

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3  -->
<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="Blank_A4_3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c2015334-3b9b-48bc-ade2-86e7e520a7f6">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="ItemDataset" uuid="0b152643-cf72-4976-95bc-192345124039">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="debit" class="java.lang.Double"/>
        <field name="credit" class="java.lang.Double"/>
    </subDataset>
    <parameter name="DataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="70" y="27" width="390" height="30" uuid="813ea731-a878-48b4-8ab6-40736164657e"/>
                <text><![CDATA[summary Report]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="261" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="200" uuid="5670f572-47f7-4ce7-b985-1a21c4f029de">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="ItemDataset" uuid="4bb2e07a-1d54-4e7c-8ddc-3adfa06cf9dd">
                        <dataSourceExpression><![CDATA[$P{DataSource}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="100" uuid="80a265a4-dbec-4453-89fd-18f8f7bb2c9b">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="adcbdb6c-29c4-401d-8508-c9110a8bfdab"/>
                                <text><![CDATA[Debit]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="6e7f26b6-cfd4-49a7-9c5f-cac28274fe12"/>
                                <textFieldExpression><![CDATA[$F{debit}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="2075644c-e62a-4d28-945a-4cb4670a6cc9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="3c7cc499-199b-4490-be8e-1ad19ee7a483"/>
                                <text><![CDATA[Credit]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="187fbede-5f3b-40bc-ac1e-b45b3f2acd21"/>
                                <textFieldExpression><![CDATA[$F{credit}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>
 

plz help me to resolve this issue ????

  

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Not sure...as I don't know phy syntax... but it seems that your array1 is an array of Strings... your array2 is also an array of Strings..,. and now you put two arrays into your arrayList.... so it could be that your arrayList now contains two arrays inside and not only the strings from array1 and array2 ?!?!? 

But as I said... not sure what in php the add Method actually does. (perhaps it adds all entries from array1/array2... but perhaps it just adds the object itself!??!)

Also you use a FIELD debit... but you just pass a PARAMETER with that name... your JRBeanCollectionDataSource is just an array of Strings... so it doesn't contain any debit field.... if you want to access the entries, you must use the built-in field named "_THIS" for the arraylist entries.

Besides that, why do you pass the JRBeancollectionDatasource as your main report datasource AND also as an parameter for your table component?  That's not a good idea as the report itself iterates through the main report datasource and also the tablecomponent would iterate through the same  datasource?!?!

hth + regards

C-Box

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...