Split type for frame - jasper-reports

Hi I am new to Jasper report and I am having a report with one text field and corresponding sub-report in the frame under detail band.Now I need to apply split type to prevent for the detail band, but I couldn't because I have subreport within detail band.Please assist me on this.Thanks in advance.
<detail>
<band height="30">
<frame>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="500" height="30" backcolor="#333333"/>
<box>
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9B64C8"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Opaque" x="0" y="0" width="166" height="30" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF">
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9BA66D"/>
<rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Helvetica" size="9" isBold="false" pdfFontName="Helvetica" pdfEncoding="CP1252" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{text1}]]></textFieldExpression>
</textField>
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="0" height="30"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA["sub.jasper"]]></subreportExpression>
</subreport>
</frame>
</band>
</detail>
Second issue:

Since the textField needs to be next to subreport and you need jasper report to try to print the record completely on 1 page.
Design the report correctly (move the subreport and give it the correct dimensions)
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="166" y="0" width="334" height="30" uuid="e812a308-674c-41dc-be83-e872752c8d6d"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{absolutePath} + "sub.jasper"]]></subreportExpression>
</subreport>
The subreport should have correct pageWidth, columnWidth and margins
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="subreport" pageWidth="334" pageHeight="842" columnWidth="332" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="775a7e35-9af8-4206-a155-b05a478c35b0">
Move the splitType="prevent" from subreport to main report.
This will need that your datasource is a JRRewindableDataSource, since jasper report will try to fill band in current page, but if it can not it will need to rewind and fill on next page. You need to implement the moveFirst() method in your datasource.

Related

Adding total on top of report [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have to design a Jasper report in iReport 5 tool with the following constraints:
I need to show the sum of each column in the header like in the image
I need to show the columns vertical like in the image
Desired output
Is it possible to design report like this?
Using the normal detail band and columnHeader band this is achieved by creating a variable with calculationType="sum" on the field you like to sum
See:
How to sum all values in a column in Jaspersoft iReport Designer?
Then display the variable using a textField in the columnHeader band, setting evaluationTime="Report" so that variable is calculated before displaying it.
To rotate a textElement vertical use the rotation attribute (rotation="Left")
Example:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ReportTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="43c90ca5-f3c3-4dda-8423-9ff1442f90e3">
<queryString>
<![CDATA[select * from mytable]]>
</queryString>
<field name="descr" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="value" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="sumValue" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{value}]]></variableExpression>
</variable>
<columnHeader>
<band height="70">
<textField>
<reportElement mode="Opaque" x="0" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="dfe13f55-12a6-4c33-b5ba-00dd61f37c96"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["TOTALE"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report" pattern="###0.00;-###0.00">
<reportElement mode="Opaque" x="100" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="ed251db0-474e-4e20-8788-3c2f08bfd1e7"/>
<box leftPadding="2" rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{sumValue}]]></textFieldExpression>
</textField>
<staticText>
<reportElement mode="Opaque" x="100" y="0" width="100" height="50" forecolor="#000000" backcolor="#CCCCCC" uuid="62b62711-8cfb-4df2-8f9e-4a34249dcc66"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left">
<font size="8"/>
</textElement>
<text><![CDATA[SESSIONS]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Immediate">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="6a009a8c-16de-451c-a0f1-516a48f793d0"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{descr}]]></textFieldExpression>
</textField>
<textField pattern="###0.00;-###0.00">
<reportElement x="100" y="0" width="100" height="20" uuid="1fccff95-408c-4364-b003-c691fefdde62"/>
<box rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Result (with some arbitrary data)
if you're not familiar with crosstab, as previously suggested, you could create a subreport just to show the column totals and put it "before" the detail band (for example in the page header band).
obviously, following this way, you will access the datasource twice, and this could could be something you want to avoid, especially if time matters.
basically, a crosstab is the better solution overall, but if you need something simpler (maybe you're not familiar with iReport) or one-shot-like you could think about a subreport
in this type of reports, you can use a crosstab, you put a field than name it monthly. Use in the columns and a field name it month in rows, and use the sum function in cells
<crosstab>
<rowGroup name="month" width="128" totalPosition="End">
...
</rowGroup>
<columnGroup name="monthlyUse" height="66">
...
</columnGroup>
<measure name="nameMeasure" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{number}]]></measureExpression>
</measure>
....
</crosstab>
the crosstab will generate a table shwoing the monthly usage with a total row

how to move a group to next page JasperReport [duplicate]

Hi I am new to Jasper report and I am having a report with one text field and corresponding sub-report in the frame under detail band.Now I need to apply split type to prevent for the detail band, but I couldn't because I have subreport within detail band.Please assist me on this.Thanks in advance.
<detail>
<band height="30">
<frame>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="500" height="30" backcolor="#333333"/>
<box>
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9B64C8"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Opaque" x="0" y="0" width="166" height="30" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF">
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9BA66D"/>
<rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Helvetica" size="9" isBold="false" pdfFontName="Helvetica" pdfEncoding="CP1252" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{text1}]]></textFieldExpression>
</textField>
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="0" height="30"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA["sub.jasper"]]></subreportExpression>
</subreport>
</frame>
</band>
</detail>
Second issue:
Since the textField needs to be next to subreport and you need jasper report to try to print the record completely on 1 page.
Design the report correctly (move the subreport and give it the correct dimensions)
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="166" y="0" width="334" height="30" uuid="e812a308-674c-41dc-be83-e872752c8d6d"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{absolutePath} + "sub.jasper"]]></subreportExpression>
</subreport>
The subreport should have correct pageWidth, columnWidth and margins
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="subreport" pageWidth="334" pageHeight="842" columnWidth="332" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="775a7e35-9af8-4206-a155-b05a478c35b0">
Move the splitType="prevent" from subreport to main report.
This will need that your datasource is a JRRewindableDataSource, since jasper report will try to fill band in current page, but if it can not it will need to rewind and fill on next page. You need to implement the moveFirst() method in your datasource.

How can I show sum of columns in column header? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have to design a Jasper report in iReport 5 tool with the following constraints:
I need to show the sum of each column in the header like in the image
I need to show the columns vertical like in the image
Desired output
Is it possible to design report like this?
Using the normal detail band and columnHeader band this is achieved by creating a variable with calculationType="sum" on the field you like to sum
See:
How to sum all values in a column in Jaspersoft iReport Designer?
Then display the variable using a textField in the columnHeader band, setting evaluationTime="Report" so that variable is calculated before displaying it.
To rotate a textElement vertical use the rotation attribute (rotation="Left")
Example:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ReportTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="43c90ca5-f3c3-4dda-8423-9ff1442f90e3">
<queryString>
<![CDATA[select * from mytable]]>
</queryString>
<field name="descr" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="value" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="sumValue" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{value}]]></variableExpression>
</variable>
<columnHeader>
<band height="70">
<textField>
<reportElement mode="Opaque" x="0" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="dfe13f55-12a6-4c33-b5ba-00dd61f37c96"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["TOTALE"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report" pattern="###0.00;-###0.00">
<reportElement mode="Opaque" x="100" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="ed251db0-474e-4e20-8788-3c2f08bfd1e7"/>
<box leftPadding="2" rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{sumValue}]]></textFieldExpression>
</textField>
<staticText>
<reportElement mode="Opaque" x="100" y="0" width="100" height="50" forecolor="#000000" backcolor="#CCCCCC" uuid="62b62711-8cfb-4df2-8f9e-4a34249dcc66"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left">
<font size="8"/>
</textElement>
<text><![CDATA[SESSIONS]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Immediate">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="6a009a8c-16de-451c-a0f1-516a48f793d0"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{descr}]]></textFieldExpression>
</textField>
<textField pattern="###0.00;-###0.00">
<reportElement x="100" y="0" width="100" height="20" uuid="1fccff95-408c-4364-b003-c691fefdde62"/>
<box rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Result (with some arbitrary data)
if you're not familiar with crosstab, as previously suggested, you could create a subreport just to show the column totals and put it "before" the detail band (for example in the page header band).
obviously, following this way, you will access the datasource twice, and this could could be something you want to avoid, especially if time matters.
basically, a crosstab is the better solution overall, but if you need something simpler (maybe you're not familiar with iReport) or one-shot-like you could think about a subreport
in this type of reports, you can use a crosstab, you put a field than name it monthly. Use in the columns and a field name it month in rows, and use the sum function in cells
<crosstab>
<rowGroup name="month" width="128" totalPosition="End">
...
</rowGroup>
<columnGroup name="monthlyUse" height="66">
...
</columnGroup>
<measure name="nameMeasure" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{number}]]></measureExpression>
</measure>
....
</crosstab>
the crosstab will generate a table shwoing the monthly usage with a total row

How to avoid using a lots of ternary operators for translation of value to text

I am using JasperReports to create some reports of a Django web application.
Let's say that I have a model that has an id and a value. This value is a Django choice so I end up in my database with only the keys and not the values (the values are in my code). To make it more clear for people that don't use Django, I end up with something like that in my database:
id value
1 'GD'
2 'VG'
3 'VG'
4 'VG'
5 'GD'
6 'AV'
7 'GD'
8 'AV'
I want to display Good instead of 'GD', Average instead of 'AV' and Very Good instead of VG in my report. I know that this can be done with two equally not desirable to me options:
Create a new table in my database that has key - value and join that in the JR query. I really hate this because I'd need to create around 10 such tables.
Use the ternary operator to display the correct value:
field.equals("GD")?"Good":(field.equals("AV")?"Average":(field.equals("VG")?"Very good":"-"))
I also hate this because it would be very complicated if I had, for instance, 10 key-value pairs.
My ideal solution would be to define a dictionary (HashMap) variable in my report that would contain all the key value pairs and then just do a DICTIONARY.get(field) to represent the field value. Can this be done ? Can you possibly propose another, better solution?
Please don't tell me to alter my database design, I know that some people won't like but it perfect for my needs.
You can solve this issue with help of Java. For example, the Guava library can help us in solving this task.
Using report's parameter
We can add the parameter of java.util.Map type and use it for extracting the value by the key (it can be the value field from your sample)
The sample:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="using_map" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e566b23d-ca97-472e-9cc3-8073573f4537">
<import value="com.google.common.collect.*"/>
<import value="com.google.common.base.*"/>
<parameter name="values" class="java.util.Map" isForPrompting="false">
<defaultValueExpression><![CDATA[new ImmutableMap.Builder<String, String>().put("GD", "Good").put("AV", "Average").build()]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="id" class="java.lang.String"/>
<field name="value" class="java.lang.String"/>
<columnHeader>
<band height="20">
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="0" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Id]]></text>
</staticText>
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="100" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Value]]></text>
</staticText>
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="200" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Value from Map]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="0" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="100" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="200" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{values}.get($F{value})]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
In this sample we use ImmutableMap.Builder class for creating and filling the Map.
The result will be (via iReport preview):
As you can see that the third columns contains null value for values that are not in Map.
Note: Don't forget to add Guava library to classpath.
Using scriptlet
You can do the same with help of Scriptlets.
You can write the simple Java class with static method, for example for getting value from the Map.
Using internationalization mechanism
May be the simplest way is to use report's internationalization support.
You can attach the properties file with values to your report.
The sample of jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="localization" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" resourceBundle="marks" uuid="a5d74b61-8d62-41ac-b874-76d6f40da79e">
<queryString>
<![CDATA[]]>
</queryString>
<field name="id" class="java.lang.String"/>
<field name="value" class="java.lang.String"/>
<columnHeader>
<band height="20">
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="0" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Id]]></text>
</staticText>
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="100" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Value]]></text>
</staticText>
<staticText>
<reportElement uuid="f23f6abc-cd9b-4415-a591-cb7a51ad0392" x="200" y="0" width="114" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Value from Properties]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="0" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="100" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8eb8bbef-430b-4ad1-b592-000fe7ccce9f" x="200" y="0" width="114" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[str($F{value})]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The marks.properties file:
GD=Good
AV=Average
VG=Very Good
And the result will be (with iReport preview):
I've used the str() method and the $R{} syntax.

Conditional Horizontal line in jasperreport between results

I'm using jasperreport 4.7.0
I have a query where I order by name then date .
Now the clients wants that when the name changes that we add an horizontal line (see attached img - red line)
Is there a way to accomplish this without duplicating the query and the fields ?
Result :
For solving your task you can use Data Grouping.
The possible steps (there are a lot of way to reach your target) for adding line are:
Create the report Group (via context menu Add Report Group in iReport) on field
Add Group Footer Band
Add Rectangle element to the Group Footer Band
Set Height, Forecolor and Backcolor for this Rectangle - drawing "red pencil line"
The sample:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="line_in_group" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f1394ead-7ad6-4371-979d-5a13d1bdde4d">
<queryString>
<![CDATA[SELECT id, city, street FROM address ORDER BY city]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="CITY" class="java.lang.String"/>
<field name="STREET" class="java.lang.String"/>
<group name="cityGroup">
<groupExpression><![CDATA[$F{CITY}]]></groupExpression>
<groupFooter>
<band height="2">
<rectangle>
<reportElement uuid="6564e743-2a45-4b51-89a5-e3ec6aee291f" x="0" y="0" width="300" height="2" forecolor="#FF0000" backcolor="#FF0000"/>
</rectangle>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="77860b22-95f6-41b6-955a-f8991843e221" x="0" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement uuid="77860b22-95f6-41b6-955a-f8991843e221" x="100" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[City]]></text>
</staticText>
<staticText>
<reportElement uuid="77860b22-95f6-41b6-955a-f8991843e221" x="200" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Street]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="7e375aa3-fab5-4761-bab9-a0570a5442b1" x="0" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="7e375aa3-fab5-4761-bab9-a0570a5442b1" x="100" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="7e375aa3-fab5-4761-bab9-a0570a5442b1" x="200" y="0" width="100" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{STREET}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The result will be (via preview in iReport):
In this sample I've create a group for the field CITY.