How to add check box to jrxml content.

1

 Hi,

I'm unable to find an option in ireport tool to add a check box to jrxml content.

my requirement is to add check box in jrxml content and at run time when I generate the pdf report out of jrxml,

I should be able to pass data which specifics whether the check box should be checked or not.

i.e (for instance for name field I could able to add a field and text box at same time at run time I'm able to pass the name while generating the report similarly I'm expecting same for my check box funtionlity).

please let us know the possible solution.

Any help is highly appreciated.

 

Thanks

 

venkatgvr's picture
Joined: Dec 6 2011 - 7:16am
Last seen: 7 years 8 months ago

3 Answers:

0
One way is to layer a checked and unchecked box image on top of each other. Now use the print when expression to determine which image to display on the report.
svenn's picture
1365
Joined: Mar 19 2007 - 5:57am
Last seen: 12 years 5 months ago
0

 

Hi,

Thank you for your quick reply.

Please can you post some sample java code to  "determine which image to display on the report." at run time as post in below thread.

Right now I'm using below sample code to pass data to text field at runtime, where name and address are text fields specified in jrxml.

1) Java Code

2) Jrxml content

Any help is highly appreciated.

Thanks.

Code:
1)<========================Java Code ==============================>
 
String path = "D:\\\\dynamic_data";
 
HashMap map = new HashMap();
 
map.put("name", "tcs");
 
map.put("address", "hyd");
 
 
jasperReport = JasperCompileManager.compileReport(path+".jrxml");
 
 
jasperPrint = JasperFillManager.fillReport(jasperReport, map, 
JasperExportManager.exportReportToPdfFile(jasperPrint, path+new JREmptyDataSourc());
 
2)<=================JRXML Content======================>
 
<?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 <a href="http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"" target="_blank">http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"</a> name=".jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43">
	<queryString language="SQL">
		<![CDATA[]]>
	</queryString>
	<field name="name" class="java.lang.String"/>
	<field name="address" class="java.lang.String"/>
	<variable name="name" class="java.lang.String"/>
	<title>
		<band height="45" splitType="Stretch"/>
	</title>
	<pageHeader>
		<band height="45" splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="25" splitType="Stretch"/>
	</columnHeader>
	<detail>
		<band height="73" splitType="Stretch">
			<staticText>
				<reportElement x="106" y="12" width="62" height="15"/>
				<textElement/>
				<text><![CDATA[Name]]></text>
			</staticText>
			<textField isBlankWhenNull="false">
				<reportElement x="224" y="12" width="72" height="15"/>
				<textElement/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="106" y="42" width="62" height="13"/>
				<textElement/>
				<text><![CDATA[Address]]></text>
			</staticText>
			<textField isBlankWhenNull="false">
				<reportElement x="224" y="41" width="72" height="15"/>
				<textElement/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{address}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="45" splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="45" splitType="Stretch"/>
	</pageFooter>
	<lastPageFooter>
		<band height="45" splitType="Stretch"/>
	</lastPageFooter>
	<summary>
		<band height="45" splitType="Stretch"/>
	</summary>
</jasperReport>
 
 
</td></tr></tbody></table>
venkatgvr's picture
Joined: Dec 6 2011 - 7:16am
Last seen: 7 years 8 months ago
0

Another way is to use unicode:

...

  <field name="COLUMN_4" class ="java.lang.Boolean" />

...

<textFieldExpression class="java.lang.String">
     <![CDATA[$F{COLUMN_4} ? "u2611" : "u2610"]]>
</textFieldExpression> 

...



Post Edited by lenalex at 08/26/2012 19:51
lenalex's picture
Joined: Jul 26 2012 - 1:37pm
Last seen: 7 years 4 weeks ago

This does not print a character with unicode u2611 (checkbox), but the string "u2611" itself; at least not with JR 5.5.0. I am using JasperStudio. I also noted that when I enter the "class=java.lang.String" in the textFieldExpression, the JasperStudio report designer automatically removes that attribute. I am using the ☐/☑ characters directly, not unicode encoded, works fine as well.

mathiaslin - 5 years 9 months ago

Need a \ character before the u to work

hacotjerome - 4 years 4 months ago

Exporting the jasper report to pdf with unicode is not printing the checkboxes.

manish.taneja01 - 6 months 4 days ago
Feedback
randomness