ureta Posted June 10, 2010 Share Posted June 10, 2010 I want to be able to define my own functions to use in expressions. How may I do that?One function that would help me a lot is something like: public static int intValueIfNullThenZero(java.lang.Number number) { return number==null?0:number.intValue(); } Is there such a function already defined? Link to comment Share on other sites More sharing options...
lucianc Posted June 17, 2010 Share Posted June 17, 2010 You can write this method into a utility class, compile it, place it on your application's classpath and use it in report expression.Currently it's not possible to define a method/function inside a report definition.Regards,Lucian Link to comment Share on other sites More sharing options...
andrewps21 Posted January 25, 2013 Share Posted January 25, 2013 How can I create a custom sql clause function like $X{MYFUNCT I would really like a function similar to $X{EQUAL that provided the null clause like the $X{IN function. IE: On null rather than IS NULL appending the truism 0 = 0, this would be very handy for optional fields in my web app, so the user can provide say 1 of 10 filters. I currently have to do this with 2 paramaters which I don't like: Plant Code (($P{plantCode} == null || $P{plantCode}.isEmpty()) ? "" : " AND mfg_plant_code =" +$P{plantCode} +" ") And in the SQL: ... where $P!{plantCodeQuery} I have written a JRSqlAbstractOptionalEqualClause and JRSqlOptionalEqualClause then a CustomExtensionsRegistryFactory. It adds this method: protected void handleNoValues(JRQueryClauseContext queryContext) { queryContext.queryBuffer().append(CLAUSE_TRUISM); } But I'm not sure what to do next to register my function sounds like I may be able to package it in a jar with a jasperreports_extension.properties but im not sure exactly. Thanks Andrew Link to comment Share on other sites More sharing options...
andrewps21 Posted January 25, 2013 Share Posted January 25, 2013 Actually i got this working, the jasperreports_extension.properties file had to be in the root of the jar, it contained this: net.sf.jasperreports.extension.registry.factory.sql.clause.functions.myfunct=com.myjob.yba.plant.report.jasperext.CustomExtensionsRegistryFactory It was then picked up in my web app. To get it working in ireport i had to go to tools -> options -> Classpath tab -> add jar :) 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