Issue for passing array parameter in jasper report

0

Hi

I am integrate jasper report using with php/javabridge.I dont need to connect any db or query.I want to passing custom array data but i am facing 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:JREmptyDataSource]). Cause: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $P{debit} VM: 1.8.0_211@http://java.oracle.com/" at: #-27 net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:244) #-26 net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591) #-25 net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559) #-24 net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1016) #-23 net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:504) #-22 net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:488) #-21 net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259) #-20 net.sf.jasperreports.engine.fill.J in http://localhost:8080/JavaBridgeTemplate721/java/Java.inc on line 223

 

Here are 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");
$arrays = ['20.00','30.00','40.00'];
$params = new Java("java.util.HashMap");
$arrayList = new java( 'java.util.ArrayList' );
    foreach( $arrays as $value ) 
    {
        $arrayList->add( $value );
    }
    $params->put('debit', $arrayList );

$class = new JavaClass("java.lang.Class");
$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");
$jasperPrint = $fillManager->fillReport($report, $params, $emptyDataSource);

$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;
}
?>

 here are my jrxm 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_2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b16306ac-31b9-44da-8668-5e30125e39b5">
    <!--<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>-->
    <parameter name="date" isForPrompting="true" class="java.lang.String" />
    <parameter name="description" isForPrompting="true" class="java.lang.String"/>
    <parameter name="debit" isForPrompting="true" class="java.lang.String"/>
    <parameter name="credit" isForPrompting="true" class="java.lang.String"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="160" y="0" width="220" height="79" uuid="bdd04fd6-61f1-44e5-be90-0be4df3ace29"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="24"/>
                </textElement>
                <text><![CDATA[Summary Report]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="75" splitType="Stretch">
            <staticText>
                <reportElement x="80" y="0" width="100" height="75" forecolor="#000000" backcolor="#62B352" uuid="86946ecb-2c90-429c-9bcf-a8713ae0c504"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <text><![CDATA[date]]></text>
            </staticText>
            <staticText>
                <reportElement x="180" y="0" width="100" height="75" backcolor="#62B352" uuid="391076d7-c81c-4b70-91c0-7d5196c7f544"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <text><![CDATA[description]]></text>
            </staticText>
            <staticText>
                <reportElement x="280" y="0" width="100" height="75" backcolor="#62B352" uuid="f3c646d6-c0ce-462d-a3d9-b44ca66eb9e6"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <text><![CDATA[debit]]></text>
            </staticText>
            <staticText>
                <reportElement x="380" y="0" width="100" height="75" backcolor="#62B352" uuid="e5f7e93f-a0c7-45c3-9cba-764aa643c30d"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <text><![CDATA[credit]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="80" y="47" width="100" height="30" uuid="04732a7a-afaf-4685-a1d2-17a823ebf2a3"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="180" y="47" width="100" height="30" uuid="095d35f9-6a51-413f-8b16-ca8970a1885f"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$P{description}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="280" y="47" width="100" height="30" uuid="567faea4-f51b-4957-bfcb-d69402d455e2"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$P{debit}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="380" y="47" width="100" height="30" uuid="9e5ae1d6-52d7-4b2c-a3e1-04540a101fbd"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$P{credit}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>
 

Plz help me this issue ???

jazebmazher728's picture
Joined: Jun 20 2019 - 8:22am
Last seen: 2 weeks 5 days ago

Hi im using array list type this is working fine but i want to render each row now in one field show array see here this is not good i want to this array show in each row not one row

jazebmazher728 - 1 month 3 days ago

3 Answers:

1

You passed a java.util.ArrayList as a parameter that is defined just as java.lang.String.... so the parameter classes do mismatch.

Not sure what you wan't to reach... but I'd first correct correct the classes in your parameters.

<parameter name="debit" isForPrompting="true" class="java.util.ArrayList"/>

hth + regards

C-Box

C-Box's picture
1669
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 days 11 hours ago
0

Hi  C-Box,

Thanks for reply your answer .I am m using array list type this is working fine but i want to render each row now in one field show array see here this is not good i want to this array show in each row not one row/

https://imgur.com/tKQiENS

 

jazebmazher728's picture
Joined: Jun 20 2019 - 8:22am
Last seen: 2 weeks 5 days ago
0

Then you should not use an JREmptyDataSource of course but instead a JRBeanCollectionDataSource from your ArrayList and use the "_THIS" as FieldName for the entries.

so the Datasource must be defined like this (sorry I just know how to define in plain java, not in php).

new JRBeanCollectionDataSource(yourArrayListOfTypeString)

and the Field in jrxml must be named "_THIS" and type of java.lang.String that you later can place somewhere in your detail band.

works fine for some of my old reports at some customers :-)

hth + regards

C-Box

C-Box's picture
1669
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 days 11 hours ago
Feedback
randomness