Actually i want to convert some calculation(eg:123 in Words as One Hundred Twenty Three). So i separately designed a jar file and in ireport designer 5.6.0 from "Tools"-->"options"-->"classpath" and added that jar and in "scriptlet" i wrote com.reporter.jasper.ConvertToWord and created a text field in report and added "$REPORT_SCRIPTLET.readNumber($V{Total})" and saved it. So When i click on preview tab its working perfect(eg:64501 as sixty four thousand five hundred one).
Now here comes the problem.I copied the report.jrxml and report.jasper and pasted it in "/WEB-INF/reports/report.jrxml" and run it on server so as to convert into PDF,DOC,XLS,XLSX it is displaying an error like this image
I am giving the code of jar file as well
package com.reporter.jasper;
import java.io.PrintStream;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
public class ConvertToWord extends JRDefaultScriptlet {
String numberInWord = "";
String inpstr = "";
int inputLength;
String temp = "";
public String readNumber(double xDouble) {
long x = (long)xDouble;
this.inpstr = "" + x;
this.inpstr = this.inpstr.trim();
this.inputLength = this.inpstr.length();
this.numberInWord = "";
if (this.inpstr.substring(0, 1).trim().equalsIgnoreCase("-")) {
this.inpstr = this.inpstr.substring(1);
--this.inputLength;
}
this.getDigits(this.inputLength);
return this.numberInWord;
}
Showing ireport images
As you can see in above image in scriptlet class "com.reporter.jasper" is package and "ConvertToWord" is class.
In the Text field $P{REPORT_SCRIPTLET}.readNumber($V{Sub Total} +$V{Output VAT and CST and Service Tax})
readNumber is method name.
So what i have to do now so that it will successfully display the data to PDF,DOC,XLS and XLSX.
Your class ConvertToWord
need to be also in the classpath of your web application, hence its not enough to add the jar to iReport, you need to added it to WEB-INF.
As a note: Can't see the whole of your ConvertToWord
class but if you are not overriding the methods of JRDefaultScriptlet
(scriplet are made to do code on beforeDetailEval()
).
Scriptlets are sequences of Java code that are executed every time a report event occurs. Values of report variables can be affected through scriptlets
there is no need to extend it you can simple do a class with a method and call this from your jrxml
public class ReportHelper{
public static synchronized String readNumber(double xDouble) {
...
}
}
and then call you class in jrxml es.
ReportHelper.readNumber($V{Sub Total} +$V{Output VAT and CST and Service Tax})
If you are using package, included full path of package definition. If you do not like it static, pass the ReportHelper class as a parameter or define it as a variable.
Naturally the class need's to always be in classpath.