Search code examples
javajasper-reports

How do you call a Java method with two parameters from JasperReports


I have a JasperReports' jrxml file that contains calls of Java method code with one int parameter. All works well with the following code using a single parameter. eventProjectid is an Integer

<textField>
    <reportElement positionType="Float" x="250" y="79" width="103" height="15"/>
    <textFieldExpression><![CDATA[com.rem40.reports.ReportUtils.getCubeXAxisLabelMaxConsequenceProject($F{eventProjectId})]]></textFieldExpression>
</textField>

I need to introduce a second parameter which does not work, all I get is a null value back. Here is the jrxml code eventProjectId is an Integer and eventType is a String.

<textField>
    <reportElement positionType="Float" x="250" y="79" width="103" height="15"/>
    <textFieldExpression><![CDATA[com.rem40.reports.ReportUtils.getCubeXAxisLabelMaxConsequenceProject($F{eventProjectId},$F{eventType})]]></textFieldExpression>
</textField>

Here is the Java code that I am trying to call

public static String getCubeXAxisLabelMaxConsequenceProject(Integer projectId, String eventType){
    ProjectEntity projectEntity = projectService.findById(projectId);

    CubeConfigEntity cubeConfigEntity=cubeConfigService.findByCubeTypeName(eventType,projectEntity.getCubeConfigName());
    if (cubeConfigEntity != null) {
        return cubeConfigEntity.getxAxisName();
    } else {
        return "";
    }
}

Just to be clear I have tried to debug the call to no available. I believe there is an issue with how the method signature try to compare from the jrxml to the Java method. In debug the single parameter methods get called but the method with two parameters never gets called.

Any help would be appreciated.


Solution

  • Your method

    com.rem40.reports.ReportUtils.getCubeXAxisLabelMaxConsequenceProject()
    

    has gone through two versions, right? One accepts a single integer argument, and the other version accepts an integer and a string as arguments. Please double check that your japser report is pointing to the new version of the class file or library.

    Also, please make sure that the two fields that you use, do have valid values with them

    $F{eventProjectId}
    $F{eventType}