当前位置: 首页 > 知识库问答 >
问题:

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

孔华池
2023-03-14

我搜索了谷歌和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 教程。使用函数库向导生成所有必要文件(使用文件

*. 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消息。属性文件

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类中看到的,我还尝试将该函数添加到现有的TextClass类中,但这也没有效果。

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

共有1个答案

贺靖
2023-03-14

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

 类似资料:
  • 我需要计算一个表中等于“X”的行数。我用什么表达来做到这一点?我如何统计每一行,不统计不符合要求的行?

  • 问题内容: 我已经用Google搜索了此错误,还没有得出为什么我会收到此错误的结论。我正在尝试用一些数据填充DataGridView。这是我的代码。 查询存储在Access中的“ project_master_query”。 如您所见,查询中根本没有Nz,所以我根本不明白为什么会这样。一旦调用dt.Load,就会发生该错误。 问题答案: 该函数最有可能在许多联接之一中引用的视图/查询中。您必须仔细

  • 在“SQL 编辑器”选项卡,你可以创建和编辑视图的 SELECT 语句 SQL。Navicat Data Modeler 为编辑视图定义提供广泛的高级功能,例如:编辑代码功能、智能自动完成代码、设置 sql 格式及更多。 【提示】当你在视图创建工具创建视图,SELECT 语句将会自动生成。 美化 SQL(仅适用于非 Essentials 版) 若要格式化凌乱的 SQL 代码到一个结构良好的脚本,你

  • 本文向大家介绍Bootstrap-table自定义可编辑每页显示记录数,包括了Bootstrap-table自定义可编辑每页显示记录数的使用技巧和注意事项,需要的朋友参考一下 写在前面:   最近在做的person功能,由于后期系统中person人数较多,不利用查找person,故需求方将要求可以自己编辑每页显示的数目,而不是固定的写死每页显示的数目。   下面先来看下bootsrap-table

  • 您好,我正在使用。 }下面是各自的xml: 在适配器获取视图:公共视图getView(int位置,视图转换视图,ViewGroup父){ ImageLoader。从这里开始的Java 在从服务器加载映像之前,如何在中显示临时映像。

  • 问题内容: 我正在使用Access数据库,并尝试加载DataTable对象,但收到错误消息。我的查询在标准访问模块内调用一个名为“ CountWeekDays”的公共函数,当通过Access本身运行时,会返回正确的结果。通过.NET应用程序调用时,为什么这不起作用? 问题答案: 只有在Access本身中运行查询时,才可以在Access查询中使用用户定义的VBA函数。如果要从.NET应用程序中运行查