2005 IR Help Posted September 3, 2006 Share Posted September 3, 2006 By: antobuccia - antobuccia HELP PLEASE: how assign a costant? 2005-12-02 02:29 Hello, I want to read from query a single value to put in a costant in a report to use it. For xample I read from query: a b---> I want to store in a costant c d at the end I want to read "b" How I can obtain this? Help help help thanks By: spalazzi - spalazzi RE: HELP PLEASE: how assign a costant? 2005-12-02 06:06 Hi If you read a value before run report you put a value into param like this: Map parameters = new HashMap(); parameters.put("paramYourValue",yourValue); byte[] bytes = JasperRunManager.runReportToPdf( reportFile.getPath(), parameters, connessione ); and in a report you use this parameter. If you read a value from report data source you can use a Scriptlet. Into an appropriate method you read a value from data source: String park=(String)this.getFieldValue("YourField"); and put this into report variable like this: this.setVariableValue("YourVariable",park); Sorry for my terrible english By: David Karnowski - karnowski RE: HELP PLEASE: how assign a costant? 2005-12-02 06:08 Is it a constant, or does it change for every row? If the constant changes for every row then you can just get it as: $F{<field_name>} If there is only a specific row that should be saved as a constant then you need to define a variable (let's call it "testval") that has an expression like this: $F{QUERY_COL}.equals("b")?$F{QUERY_COL}:$V{testval} You then refer to your "constant" as $V{testval} By: antobuccia - antobuccia RE: HELP PLEASE: how assign a costant? 2005-12-09 06:11 I use this SCRIPTLET to take a specifica value from a datasource (an idexed value) import java.util.ArrayList; import net.sf.jasperreports.engine.JRDefaultScriptlet; import net.sf.jasperreports.engine.JRScriptletException; public class Elements extends JRDefaultScriptlet{ ArrayList al = new ArrayList(); public int addElement(Object o)throws JRScriptletException { al.add(o); return 1; } public Double getElementAt(int index)throws JRScriptletException{ return (Double)al.get(index); } } ----------------------------------------- use this to capture a value: (((Elements)$P{REPORT_SCRIPTLET}).getElementAt($P{nr_value}.intValue())) ----------------------------------------- I want to store this value in a variable but: java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:508) at java.util.ArrayList.get(ArrayList.java:320) at Elements.getElementAt(Elements.java:15) at report_test.evaluate(report_test:175) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:461) at net.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(JRCalculator.java:147) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:576) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:210) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:118) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:622) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:489) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:76) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:163) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:550) at java.lang.Thread.run(Thread.java:536) --------------------------------------- instead in a parameter it doesn't goes in error,but when I want to show it I have null Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now