Jaspersoft自定义函数未在表达式编辑器中显示

时间:2014-12-04 08:49:43

标签: jasper-reports jaspersoft-studio

我搜索过Google和Stackoverflow,但我无法找到问题的答案。

我目前正在使用Jaspersoft Studio 5.6.2 final,我试图在我的表达式编辑器中显示一个自定义函数,但是我尝试的只是无法获得类别和功能秀。

我开始关注https://community.jaspersoft.com/wiki/jaspersoft-studio-expression-editor-how-extend-it-and-contribute-your-own-functions-part-2-0上的教程。使用Functions Librry向导生成所有necesarry文件(使用File> New> Other> Jaspersoft Studio>函数库)并轻松创建函数。

应该配置* .properties文件的方式在教程中不是很清楚所以我也查看了http://jasperreports.sourceforge.net/sample.reference/functions/index.html#functions,在对属性文件进行调整后,自定义函数和类别是还没有显示

我尝试直接在Jaspersoft中测试我的代码,将其导出到jar文件,在另一个Eclipse中创建jar文件并重新启动Jaspersoft Studio。什么都行不通。

以下是我的文件内容。

类别类

package net.sf.jasperreports.functions.custom;

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

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

包含函数的类

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文件

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

正如您在AbleFunctions类中所看到的,我还试图将该函数添加到现有的TextCategory类中,但这也没有效果。

有人知道问题是什么吗?这已经花了我几天没有任何成功,所以任何帮助都会很棒!

1 个答案:

答案 0 :(得分:-1)

这似乎是使用最新版社区版修复的旧错误:https://community.jaspersoft.com/questions/848371/custom-functions