Jaspersoft custom function not showing in the expression editor

2.6k Views Asked by At

I've searched google and Stackoverflow but I just can't find an answer to my question.

I'm currently using Jaspersoft Studio 5.6.2 final and I'm trying to get a custom function to show up in my Expression Editor, but what ever I try I just cannot get the Category and function to show.

I started following the tutorial on https://community.jaspersoft.com/wiki/jaspersoft-studio-expression-editor-how-extend-it-and-contribute-your-own-functions-part-2-0. Generating all the necesarry files using the Functions Librry wizard (using File > New > Other > Jaspersoft Studio > Functions Library) and creating the function itself was easy.

The way the *.properties files are supposed to be configured is not very clear in the tutorial so I've also looked at http://jasperreports.sourceforge.net/sample.reference/functions/index.html#functions, after making adjustments to the properties file the custom function and category are still not showing

I've tried testing my code directly inside Jaspersoft, exporting it to a jar file, creating the jar file in another Eclipse and restarting Jaspersoft Studio. Nothing works.

Below is are the contents of my files.

The category class

package net.sf.jasperreports.functions.custom;

import net.sf.jasperreports.functions.annotations.FunctionCategory;

// I've also tried @FunctionCategory("Able")
@FunctionCategory()
public final class Able {
}

The class containing the function

package net.sf.jasperreports.functions.custom;

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 net.sf.jasperreports.functions.standard.TextCategory;

@FunctionCategories({ Able.class, TextCategory.class })
public final class AbleFunctions 
{
    /**
     * Returns a barcode the custom font IDAutomationSHI25M will understand based on the page number
     * and whether or not the current pagenumber is the lastpage 
     * @param pagenumber
     * @param lastpage
     * @return
     */
    @Function("CREATE_BARCODE")
    @FunctionParameters({
        @FunctionParameter("pagenumber"), 
        @FunctionParameter("lastpage")})
    public static String CREATE_BARCODE(Integer pagenumber, boolean lastpage)
    {
        String[] barcodeArray = {"!","\"", "#", "$", "%", "&", "(", ")", "*", "+", ",", "-", ".","/", 
                "0", "1", "2", "3", "4", "5", "6", "7", "8","9", ":", ";", "<", "=", ">", "?", "@", 
                "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
                "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^","_", "`","a", "b", 
                "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", 
                "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "┼", "ã", "Ã", "╚", "╔", "╩"};

        String onePage = barcodeArray[1] + barcodeArray[1];
        String middlePagePrefix = barcodeArray[0];
        String lastPagePrefix = barcodeArray[10];

        // There are a couple of specific conditions that will generate a specific outcome.
        // Checking these conditions first
        if (pagenumber == 1 && lastpage) {
            return onePage;
        } else if (pagenumber > 1 && lastpage) {
            return lastPagePrefix + barcodeArray[pagenumber];
        } else {
            return middlePagePrefix + barcodeArray[pagenumber];
        }
    }
}

jasperreports_messages.properties file

net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.description            = Provide the current pagenumber and a boolean property telling if this is the lastpage and this method will return a string that can be turned in a barcode
net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.lastpage.description   = A boolean value telling if the current page number belongs to the lastpage or not
net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.lastpage.name          = lastpage
net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.name                   = CREATE_BARCODE
net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.pagenumber.description = The current page number
net.sf.jasperreports.functions.custom.Able.CREATE_BARCODE.pagenumber.name        = pagenumber
net.sf.jasperreports.functions.custom.Able.description                           = Custom Able functions for Jasperreports
net.sf.jasperreports.functions.custom.Able.name                                  = Able

jasperreports_extension.properties

net.sf.jasperreports.extension.registry.factory.functions=net.sf.jasperreports.functions.FunctionsRegistryFactory
net.sf.jasperreports.extension.functions.ablefunctions=eu.able.functions.AbleFunctions

As you can see in the AbleFunctions class I've also tried to add the function to the existing TextCategory class, but this also has no effect.

Does anybody have a clue what the problem could be? This is already taking me days without any succes so any help would be great!

1

There are 1 best solutions below

0
On

This seems to be an old bug fixed with the latest version of the Community Edition: https://community.jaspersoft.com/questions/848371/custom-functions