It is possible to use your own functions in a formula of an report, when these functions are implemented as methods in public Java class(es). To use user defined functions in a formula follow the next steps:
<classname> to the property 'Formula Expander Class', where classname means the fully qualified name of the class. This can also be a semicolon separated list of class names. Please check the classpath used by i-net Clear Reports and the package structure if ClassNotFoundException appears at runtime. Alternatively you can use the API to modify the used configuration.static public String aFunction(String str) { return "[" + str + "]"; } static public Number aFunction(Number d) { return new Double( 2.0 * d.doubleValue()); } static public String aFunctionToo( Object obj) { if (obj instanceof String) { return ((String) obj) + " Ha"; } else { return null; } } static public Number aFunction(Number i) { return new Integer(i.intValue() * 2); } public Object[] aFunction(Object[] i){ Object[] o = new Object[i.length]; for (int k=0;k<i.length;k++) { o[k] = i[i.length-k-1]; } return o; } public Boolean aFunction( Number i, FormulaRange range ){ double lower = ((Number)range.getFrom()).doubleValue(); double upper = ((Number)range.getTo()).doubleValue(); double n = i.doubleValue(); if( range.isLowLimitIncluded() ? n < lower : n <= lower ){ return Boolean.FALSE; } if( range.isHighLimitIncluded() ? n > upper : n >= upper ){ return Boolean.FALSE; } return Boolean.TRUE; } } // Note: This function should do a type check on the range bounds first.
You can find more samples in the Java code sample: FormulaSample.
i-net software strives to provide accurate product documentation. Please give us your feedback using the form below.
NOTE: This form is for documentation feedback only. For technical assistance, please send an email to clearreports@inetsoftware.de.