我搜索了谷歌和 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 向导(使用 File > New > Other > Jaspersoft Studio > Functions Library)生成所有必需的文件并创建函数本身很容易。
*.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 类中,但这也没有任何效果。
有人知道问题可能是什么吗?这已经花了我好几天没有任何成功,所以任何帮助都会很棒!