Jump to content
We've recently updated our Privacy Statement, available here ×

Adding new functions to expression editor according to the tutorial


anderl

Recommended Posts

I tried to add new function to my Report in Jaspersoft Studiop according to the tutorial: Expression Editor how to extend it and contribute your own functions.

With this Method Jaspersoft studio adds some example Function too and I wanted to begin by adding my functionen to the .java files provided but it doesn't work.

Either my expressions don't show up or the expression editor does not work at all. I even had to reinstall the JRE to fix the expression editor after one attempt.

 

What I tried:

-rebuilding the whole Report directory by pressing ctrl+b

-constructing it completely from scratch

-Adding it to one of the files provided by the wizard (New->other->Funtion package) in the source folder

 

I think it has something to do with the compiling process but I#m not sure and I don't know how to make Jaspersoft studio to compile my files.

 

My code and my outline below. ROUND_MW is the function I wanted to add. The function is far from complete but it should be valid code.

package unilimeFunctions;import net.sf.jasperreports.functions.annotations.Function;import net.sf.jasperreports.functions.annotations.FunctionCategories;import net.sf.jasperreports.functions.annotations.FunctionParameter;import net.sf.jasperreports.functions.annotations.FunctionParameters;import java.text.DecimalFormat;@FunctionCategories({ UnilimeReportFunctions.class })public class UnilimeFunctions {        @Function("ROUND_MW")    @FunctionParameters({ @FunctionParameter("DecimalNumber"), @FunctionParameter("DecimalPlaces")})    public static Double ROUND_MW(Double DecimalNumber, Integer DecimalPlaces) {        DecimalFormat df = new DecimalFormat();        return 15.0;        }        @Function("HELLO_WORLD_MSG")    public static String HELLO_WORLD_MSG() {        return "Hello World!";    }    @Function("REPEAT_MSG")    @FunctionParameters({ @FunctionParameter("message"), @FunctionParameter("times"),            @FunctionParameter("forceUpperCase") })    public static String REPEAT_MSG(String message, Integer times) {        return REPEAT_MSG(message, times, false);    }    public static String REPEAT_MSG(String message, Integer times, Boolean forceUpperCase) {        StringBuffer sb = new StringBuffer();        for (int i = 0; i < times; i++) {            sb.append(message).append("n");        }        String txt = sb.toString();        if (forceUpperCase) {            txt = txt.toUpperCase();        }        return txt;    }}[/code]

converted-file.png.fb129226135dcff062f2df70507504b4.pngI would really aprecciate any kind of help. Even where I have to start looking

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Thank you for your response. I'm using Jaspersoft Studio 6.5.1.

The first java file named unilimeFunctions:

package unilimeFunctions;import net.sf.jasperreports.functions.annotations.Function;import net.sf.jasperreports.functions.annotations.FunctionCategories;import net.sf.jasperreports.functions.annotations.FunctionParameter;import net.sf.jasperreports.functions.annotations.FunctionParameters;import java.text.DecimalFormat;@FunctionCategories({ UnilimeReportFunctions.class })public class UnilimeFunctions {        @Function("ROUND_MW")    @FunctionParameters({ @FunctionParameter("DecimalNumber"), @FunctionParameter("DecimalPlaces")})    public static Double ROUND_MW(Double DecimalNumber, Integer DecimalPlaces) {        DecimalFormat df = new DecimalFormat();        return 15.0;        }        @Function("HELLO_WORLD_MSG")    public static String HELLO_WORLD_MSG() {        return "Hello World!";    }    @Function("REPEAT_MSG")    @FunctionParameters({ @FunctionParameter("message"), @FunctionParameter("times"),            @FunctionParameter("forceUpperCase") })    public static String REPEAT_MSG(String message, Integer times) {        return REPEAT_MSG(message, times, false);    }    public static String REPEAT_MSG(String message, Integer times, Boolean forceUpperCase) {        StringBuffer sb = new StringBuffer();        for (int i = 0; i < times; i++) {            sb.append(message).append("n");        }        String txt = sb.toString();        if (forceUpperCase) {            txt = txt.toUpperCase();        }        return txt;    }}[/code]

The second one, unilimeReportFunctions, is empty.

 

As mentioned before: This is the output that I got from following the tutorial. I only added the function ROUND_MW

 

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...