anderl Posted March 8, 2018 Share Posted March 8, 2018 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]I would really aprecciate any kind of help. Even where I have to start looking Link to comment Share on other sites More sharing options...
Massimo Rabbi Posted March 9, 2018 Share Posted March 9, 2018 Can you detail which version of Studio you are using? Could you provide both the Java files. I see errors in the category one too.Regards,Massimo. Link to comment Share on other sites More sharing options...
anderl Posted March 12, 2018 Author Share Posted March 12, 2018 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 More sharing options...
Massimo Rabbi Posted March 13, 2018 Share Posted March 13, 2018 Did you modify the dedicated message properties? What do you mean with "The second one, unilimeReportFunctions, is empty."?I think it's better you attach a zip with your sample project. Thanks.Regards,Massimo. Link to comment Share on other sites More sharing options...
anderl Posted March 13, 2018 Author Share Posted March 13, 2018 Here is a link to the zip Archive:https://we.tl/yQRoQ8re1f Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now