Jump to content

User Defined Functions?


ureta

Recommended Posts

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

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 years later...

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

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

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