Passing Variable value to Parameter -End of report

0
Dear frnds,

I am getting a calculated value in my variable. And I need to get that value into a parameter which will be handled by servlet.

I need to get this value at the end of the report. I tried all the settings of "Reset Type" values like report, column..etc. But I am just getting the "null" value into that.

Please help me in getting a solution.

With Regards
Sridhar Yadavilli
yadavillisridhar's picture
Joined: Jan 2 2007 - 10:06pm
Last seen: 8 years 8 months ago

8 Answers:

0

You need scriptlet magic.

First create a scriptlet to do the value passing. This example takes an Integer variable and sets a String parameter, then returns the String contents of the parameter so it can be displayed in a text field:

import net.sf.jasperreports.engine.*;
 
public class myScriptlet extends it.businesslogic.ireport.IReportScriptlet {
    /* Creates a new instance of JRIreportDefaultScriptlet */
    public myScriptlet() {
    }
    public String CopyVarToPar(Integer v) throws JRScriptletException {
        parametersMap.put("myParameter", v.intValue());
        Integer p = (Integer)parametersMap.get("myParameter");
        return (String)p.toString();
    }
}

In the LastPageFooter or Summary band you need to define a Text Field with the Textfield Expression set to $P{REPORT_SCRIPTLET}.CopyVarToPar($V{myVariable})


The example above will display the contents of the parameter (which will contain the contents of the variable). If you don't want to display anything then your scriplet need not return anything :

import net.sf.jasperreports.engine.*;
 
public class myScriptlet extends it.businesslogic.ireport.IReportScriptlet {
    /** Creates a new instance of JRIreportDefaultScriptlet */
    public myScriptlet() {
    }
 
    String CopyVarToPar(Integer v) throws JRScriptletException {
        parametersMap.put("myParameter", v.intValue());
        return (java.lang.String)(null);
    }
}

You can then set the Text Field to Blank When Null and Remove Line When Blank

Post edited by: jmurray, at: 2007/01/04 04:17

jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 14 years 9 months ago
0
BTW, you will receive a compilation warning like this:


4537029 [Thread-57] INFO design.JRJdk13Compiler - Note: myScriptlet.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Â


because the scriptlet directly manipulates the parametersMap hashmap. Unfortunately there is no setParametervalue() method available, so the direct manipulation of the hashmap is the only way to get the job done.
Post edited by: jmurray, at: 2007/01/03 23:21
jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 14 years 9 months ago
0
Thanks alot for the help.

I have done as you said and I got com.sun.javac.Main CassnotFound Exception. I have set the Classpath[Added the path of tools.jar]...

Then I recompiled, Now I got the java.lang.reflect.InvocationTargetException.

I googled the error. But couldnt able to find a solution.

Can anyone help me in this..
yadavillisridhar's picture
Joined: Jan 2 2007 - 10:06pm
Last seen: 8 years 8 months ago
0
Information about the InvocationTargetException can be found in the Exception Summary section of this page:
http://java.sun.com/j2se/1.3/docs/api/java/lang/reflect/package-summary....



I am unable to generate the error so cannot offer any help resolving this issue other than suggesting you make sure these files all exist in the lib directory:


ireport.jar
itext.jar
jasperreports.jar
jcommon.jar
jfreechart.jar
tools.jar
xalan.jar


and that there is only one version of each of them in the lib directory and any other directories specified in the classpath.


.
Post edited by: jmurray, at: 2007/01/04 04:20
jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 14 years 9 months ago
0
Anyhow I will try for that Murray.

Thanks alot for your help.

I got an another issue.

I am using crosstab in my report. Can I limit the number of records printed in the each page of the report?



Thanking you in anticipation.
yadavillisridhar's picture
Joined: Jan 2 2007 - 10:06pm
Last seen: 8 years 8 months ago
0
I don't know. Best post you crosstab question in the main forum.
jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 14 years 9 months ago
0
I managed to generate a InvocationTargetException by creating a duplicate field definition.

When the compiler fails with this type of exception (wrapper) you need to scroll down through the exception log to find the root cause. In my case it was very clear:

net.sf.jasperreports.engine.JRException: Duplicate declaration of field : ReceiptNum
jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 14 years 9 months ago
0

Hi.......

I am getting java.lang.reflect.InvocationTargetException while compiling my report which is having a scriplet. How to avoid that. The log file is as below :

Compiling scriptlet source file... C:iReport-1.2.5SL43Scriptlet.java
Error compiling the Scriptlet java source!
 
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at net.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:88)
 at net.sf.jasperreports.engine.design.JRAbstractMultiClassCompiler.compileClass(JRAbstractMultiClassCompiler.java:45)
 at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:286)
 at java.lang.Thread.run(Unknown Source)
 
Caused by:
 
java.lang.VerifyError: class com.sun.tools.javac.jvm.Target overrides final method
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$100(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 at com.sun.tools.javac.Main.compile(Main.java:52)
 
 ... 8 more
 
NESTED BY: 
 
net.sf.jasperreports.engine.JRException: Error compiling report java source files : C: iReport-1.2.5SL43Scriptlet.java
 at net.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:119)
 at net.sf.jasperreports.engine.design.JRAbstractMultiClassCompiler.compileClass(JRAbstractMultiClassCompiler.java:45)
 at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:286)
 at java.lang.Thread.run(Unknown Source)
 
Caused by:
 
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at net.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:88)
 
 ... 3 more
 
Caused by:
 
java.lang.VerifyError: class com.sun.tools.javac.jvm.Target overrides final method
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$100(Unknowxan Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 at com.sun.tools.javac.Main.compile(Main.java:52)
 
 ... 8 more
 
Compilation running time : 47

Please help me in getting solution........

Thanking you,

Sridhar Yadavilli

yadavillisridhar's picture
Joined: Jan 2 2007 - 10:06pm
Last seen: 8 years 8 months ago
Feedback
randomness