Using jxls, I'm trying to use use a custom processing function in a template with the following code :
Transformer transformer = TransformerFactory.createTransformer(template, outputStream);
JexlExpressionEvaluator evaluator = (JexlExpressionEvaluator) transformer.getTransformationConfig().getExpressionEvaluator();
Map<String, Object> functions = new HashMap<>();
functions.put("functions", new XlsExportUtils());
JexlEngine customJexlEngine = new JexlBuilder().namespaces(functions).create();
evaluator.setJexlEngine(customJexlEngine);
JxlsHelper.getInstance().processTemplate(context, transformer);
My method in the XlsExportUtils class is a simple testing method :
public String test() {
return "toto";
}
And I'm trying several ways to call it in the template but none of them seem to work :
A dot notation : ${functions.test()}
Or a colon ":" notation as seen in another example on the internet :
${functions:test()}
Both returns :
unsolvable function/method 'test'
Same for a method taking an argument. In this case, the lib tries to resolve the type of argument depending on the expression.
For example, if I hardcode an int argument like : test(1), I get the error
unsolvable function/method 'test(Short)'
If I hardcode a bigger value, the argument in the error message changes to "Long"
If I pass a variable corresponding to an Integer : Ex: ${functions:test(myObject.myInt)}
It wierdly resolves the argument into a Float, returning the error message :
unsolvable function/method 'test(Float)'
Version : 2.12.0