Scriptlet: getParameterValue() works in studio, fails on server

0

Greetings,

 

I am quite new to JasperReport and currently working on some Reports with Jaspersoft Studio 6.5.1 and deploy these Reports on a JasperReport Server 6.4.2 from Bitnami JasperReport Stack both are community editions.

I try to create my Report with dynamic SQL and I have a bunch of parameters for different filters.

These parameters are getting used in a scriptlet which gets them with the JRAbstractScriptlet.getParameterValue(String) method.

After gathering all parameters I build the string where all the conditions are put into a WHERE clause.

I store this resulting string from the method into a new parameter called ‘Query’ which evaluation time is set on LATE and the default value is the call of the method.

That new parameter ‘Query’ is used then in the real Query from the Dataset.

This whole construct works perfectly fine in the Jaspersoft Studio but crashes when deployed on the JasperReport Server.

When the Server executing the scriptlet, the getParameterValue() function is throwing a NullPointerException if the evaluation time from all the filter parameters is set on NULL or LATE and returns the default values of the parameters if the evaluation time is set on EARLY.

I assume that the input controls from the server give their values to the parameters from the report AFTER the scriptlet is executed.

Is there a way to see in which order the server is filling parameters and executing scriptlets?

Do you have any other idea what it can be? (something with Tomcat maybe?)

Can i somehow paste a image here in the forum?

I paste the (pseudo/simplified) code from my scriptlet below:

 

package functions;
 
import java.lang.reflect.Field;
 
import net.sf.jasperreports.engine.JRAbstractScriptlet;
 
 
import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
 
public class QueryBuilder extends JRDefaultScriptlet
{    
    private String buildSQLList(String parameter) //Example: Input is like i1,i2,i3 and output is 'i1','i2','i3'
    {
        String result = "";
        String[] parts = parameter.split(",");
        for (String string : parts) 
        {
            result += "'" + string + "',";
        }
        result = result.subSequence(0, result.length()-1).toString();
        return result;
    }
    public String buildQuery() 
    {
        String result= "";
        //====================PARAMETERS====================
        String firstparameter                    = "";
        String secondparameter                     = "";
        //==================================================
 
 
        //====================TRY LOAD PARAMETER FROM ENGINE====================
        try{firstparameter = getParameterValue("Parameter#1").toString();  }catch(Exception e) {e.printStackTrace();}
        try{secondparameter = getParameterValue("Parameter#2").toString(); }catch(Exception e) {e.printStackTrace();}
        //======================================================================
 
 
        //====================TURN THE SIMPLE PARAMETER VALUE INTO A WHERE CONDITION OR AN EMPTY IF THERE IS NO VALUE====================
        Parameter#1             = (Parameter#1 != "")     ?     "\n COLUMN#1 = '" + Parameter#1 +"'" : "";
        Parameter#2         = (Parameter#2 != "")     ?     "\n AND (COLUMN#2 IN(" + this.buildSQLList(Parameter#2) +"))" : "";
        //===============================================================================================================================
 
 
        //====================BUILD RESULT====================
        result += Parameter#1 + Parameter#2;
        //====================================================
        return result;
    }    
}

CoffeeAndCode's picture
Joined: May 4 2018 - 1:44am
Last seen: 1 year 6 months ago

0 Answers:

No answers yet
Feedback