Jasper subdataset parameter incrementing unexpectedly - jasper-reports

I have a Jasper report with a Pie Chart that is being drawn at the group_footer for my group "contract". The contract group is returning two rows at this time and I am using the contract id which are integers 1 and 3. When I print the contract id in the group_footer, it prints 1 and then 3 as expected. However, when I try and pass the same contract id into a datasetrun for the Pie Chart in the very same group_footer, the value being passed into the parameter is 3 for both charts (I am viewing the SQL using statement logging on the db server). I can not figure out how it's sending the second value "3" both times. As I mentioned, the contract id prints on the report right next to the chart as "1" the first item in the group.
Here is my subDataset with the parameter "currentContractId":
<subDataset name="age_stats" uuid="44847f01-474b-4228-96e9-ea5ab992f67b">
<property name="....data.defaultdataadapter" value="database"/>
<parameter name="currentContractId" class="...Integer" isForPrompting="false"/>
<queryString>
<![CDATA[SELECT * FROM table WHERE column = $P{currentContractId}]]>
</queryString>
<field name="age" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
</subDataset>
Here is the chart datasetrun where I am trying to pass the field "id" into the "currentContractId" parameter for my subDataset above:
<pieDataset maxCount="6">
<dataset>
<datasetRun subDataset="age_stats" uuid="75d14f7c-f94e-4749-860f-ea95c2134e9c">
<datasetParameter name="currentContractId">
<datasetParameterExpression><![CDATA[$F{id}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
</dataset>
</pieDataset>
I am happy to provide the full jrxml to anyone who thinks it would be helpful.

I found the problem. Aside from the options in the chart dataset wizard, there is a seperate option under the chart properties called "Evaluation Time". I set the Evaluation Time option to my Group "contract" and the problem was resolved.

Related

jasper decimal separator being ignored

In a jasper report I use a JSON datasource.
This datasource contains numbers (e.g. 159.994).
There is a field of class java.lang.double (let's call it "doubleField") and a text field with this field and a pattern ("#,##0.00 ¤ (brutto)").
The pattern works fine (german currency format) but if I print out just the value of the doubleField the expected output would be "195,99" or "159.994".
But in fact it is "159.994,00" or "159994.0".
There was a solution changing the language of the report from "groovy" to "JavaScript" but this won't help and is also not applicable.
There is a "quick&dirty" solution (without being quick) to just take the JSON value as a String and then cast it to a double in the text field. This works fine but it's dirty and not really quick.
Any ideas?
I have a Jasper report definition. I'm just including a few things from that report definition that I think might be relevant to your problem.
First, I have several field definitions. Here are two of them:
<field name="FundFixedBeginningBalance" class="java.lang.Double">
<fieldDescription>
<![CDATA[FundFixedBeginningBalance/FundFixedBeginningBalanceValue]]>
</fieldDescription>
</field>
<field name="FundNonFixedBeginningBalance" class="java.lang.Double">
<fieldDescription>
<![CDATA[FundNonFixedBeginningBalance/FundNonFixedBeginningBalanceValue]]>
</fieldDescription>
</field>
Note how both are defined with class="java.lang.Double". I'm using XPath expressions because my data is in XML, but that is not fundamentally different from JSON. Later, in the report layout section I have:
<textField pattern="#,##0.00 ;(#,##0.00)" isBlankWhenNull="true">
<reportElement positionType="Float" x="368" y="52" width="100" height="14" uuid="deac984d-39b8-49f4-b4d2-28e66681c098">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{FundFixedBeginningBalance} + $F{FundNonFixedBeginningBalance}]]></textFieldExpression>
</textField>
Notice there is no casting within the textFieldExpression element; just substituting both fields in with $F and adding them together (and this prints correctly). Are you doing something different?

How to populate list with values without java? - JRXML or REST

<parameter name="Bla" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[new ArrayList<String>() {{ add("A");}}]]></defaultValueExpression>
</parameter>
I want to see how I can populate list parameter without using java? Is that possible to do?
Error:
java.lang.NoClassDefFoundError: report_1405012032235_427203 (wrong name: report_1405012032235_427203$3)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClass(JRClassLoader.java:339)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassFromBytes(JRClassLoader.java:263)
at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:102)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(JRAbstractCompiler.java:340)
at net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(JasperCompileManager.java:378)
at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:462)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:405)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:89)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:104)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:62)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
at net.sf.jasperreports.engine.fill.BaseFillHandle.<init>(BaseFillHandle.java:75)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.<init>(AsynchronousFillHandle.java:98)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.<init>(AsynchronousFillHandle.java:87)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.createHandle(AsynchronousFillHandle.java:189)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:330)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
'report' is report name.
It only works when I don't specify inline values like:
new ArrayList<String>()
I am on Jasper Server so effectively I want to understand how do I populate the values for this kind of parameters.
I will be happy even with defaultValueExpression which creates and add values inside. If you can go beyond and show how to do rest call for report unit for such jrxml, I will award extra rep.
Try following code:
<parameter name="Bla" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[new ArrayList<String>().add(new String("A"))]]></defaultValueExpression>
</parameter>
You can initialize a list parameter using java with default expression:
<parameter name="paramName" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[Arrays.asList(new String[]{"value0","value1","value2"})]]></defaultValueExpression>
</parameter>
Note that you must add enough values as you use in the report, if not you would get an out of index exception.

Pass a variable from table to parent report

I have one child table inside report.. Inside that table I have a variable that I want to use in parent report. Is it possible to pass it from table up to parent report?
Thank you
You can pass the final value of a table subdataset variable back to the main report. The value is returned at the end of each table instantiation.
The report JRXML would look something like the following. You can use a different calculation type if you want to sum/aggregate the returned value in the main report.
<subDataset name="TableDataset">
<variable name="SubdatasetVariable" class="java.lang.Integer" ../>
</subDataset>
<variable name="AVariable" class="java.lang.Integer" calculation="System"/>
<jr:table >
<datasetRun subDataset="TableDataset">
<returnValue fromVariable="SubdatasetVariable" toVariable="AVariable" calculation="Nothing"/>
..

Dynamic styling of row headers in JasperReports Crosstab

I am attempting to generate a cross tab report using JasperReports. The column contains time periods and the row contains different group by conditions. Now I need to change the styling of the row headers based on the level. For example, in the grid shown below, web and email need to be in bold while the other row headers are as is.
Now, I have a field in the bean that lets me decide if I should make the text bold or not, so I tried to use this in a conditional style as below
<style name="rowStyle" hAlign="Center">
<conditionalStyle>
<conditionExpression><![CDATA[$V{level}.intValue() != 0]]></conditionExpression>
<style isBold="true" hAlign="Left"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{level}.intValue() == 0]]></conditionExpression>
<style isBold="false" hAlign="Right"/>
</conditionalStyle>
</style>
and I have a field and a measure expression corresponding to this
<field name="level" class="java.lang.Integer"/>
<measure name="level" class="java.lang.Integer">
<measureExpression><![CDATA[$F{level}]]></measureExpression>
</measure>
However this style does nothing when used inside the crosstabRowHeader, it takes effect only inside crosstabCell.
So my questions are
Is anyway for me to use a conditional style inside the crosstabRowHeader?
More specifically, can I access any bean property within the crosstabRowHeader?
Managed to figure this out after all.
So the issue is to be able to access a property from the bean within the crosstabrowheader (or any other cross tab headers).
To do this first create a field corresponding to the bean as so -
<field name="voBean" class="com.jasper.reports.voBean">
<fieldDescription>_THIS</fieldDescription>
</field>
Then in the headers, specify this bean as the bucket class.
<rowGroup name="voBean" width="200">
<bucket class="com.jasper.reports.voBean">
<bucketExpression><![CDATA[$F{voBean}]]></bucketExpression>
</bucket>
You can now start to access any property on the bean as below
<textFieldExpression><![CDATA[$V{voBean}.getRowName()]]></textFieldExpression>
Hope this helps anybody else with the same problem.

Accessing/importing user defined classes in jrxml

Have anyone tried to import user defined classes in jasper report (.jrxml file)?
I want to use some (user defined) Util class inside my jasper report to cook some bean attributes. I am using Javabean datasource
Please let me know if you need further clarification.
syntax to import class is
<import value="java.util.HashMap"/>
I want to use
<import value="mypackage.MyUtil" />
....
....
<field name="myVar" class="java.lang.String">
<fieldDescription><![CDATA[MyUtil.cook(myData)]]>
</fieldDescription>
</field>
The simple definition for MyUtil.java could be
package mypackage;
public class MyUtil
{
public static String cook(String data)
{
return data + "_cooked";
}
}
I think I should have tried sufficiently before asking this.
There is nothing extra needed apart from
There are two sections in jrxml:
1. Defining fields from javabean source
2. Using fields defined in step 1. to populate values in detail band
I was trying to cook the value of javabean members even before they are used to create fields
So, jasper was trying to parse that 'expression' as javabean member.
Following is wrong
<field name="myVar" class="java.lang.String">
<fieldDescription><![CDATA[MyUtil.cook(myData)]]>
</fieldDescription>
</field>
When I used the Util class on field value, it worked.
<textField>
<reportElement x="200" y="0" width="100" height="13"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[MyUtil.cook($F{myVar})]]>
</textFieldExpression>
</textField>
Thanks
Nayn
You have to set the classpath in your iReport. It depends on its version, but is generally under Settings/Classpath