How to remove extra space between textfield in JasperReports?

You can use 3 textField elements with isRemoveLineWhenBlank property set to true value. The sample (jrxml file): <?xml version=”1.0″ encoding=”UTF-8″?> <jasperReport .. topMargin=”0″ bottomMargin=”0″> <parameter name=”parameter1″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <parameter name=”parameter2″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <parameter name=”parameter3″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <title> <band height=”102″ splitType=”Stretch”> <textField isBlankWhenNull=”true”> <reportElement x=”163″ y=”9″ width=”100″ height=”20″ isRemoveLineWhenBlank=”true”/> <box> <topPen lineWidth=”1.0″/> <leftPen … Read more

Generate Jasper report with subreport from java

You can compile the subreport like the simple report – with help of JasperCompileManager.compileReport(java.lang.String sourceFileName) method, for example. After that you can pass the compiled subreport as parameter to the master report. The sample: JasperReport jasperMasterReport = JasperCompileManager.compileReport(masterReportSource); JasperReport jasperSubReport = JasperCompileManager.compileReport(subReportSource); Map<String, Object> parameters = new HashMap()<String, Object>; parameters.put(“subreportParameter”, jasperSubReport); JasperFillManager.fillReportToFile(jasperMasterReport, parameters, outputFileName, connection); … Read more

Unable to retrieve value from a JavaBean while generating reports using JasperReports API

The solution is very simple – you should change the access modifier of JavaBean class to public. Like this: public class EventBean { private String name; private String count; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCount() { return count; } public void setCount(String … Read more

Adding table border in jasperreports

You can add borders with help of GUI designer (iReport, for example) or you can add the box element manually (edit the jrxml file) like in this sample: <textField> <reportElement x=”29″ y=”17″ width=”100″ height=”20″/> <box> <topPen lineWidth=”1.0″/> <leftPen lineWidth=”1.0″/> <bottomPen lineWidth=”1.0″/> <rightPen lineWidth=”1.0″/> </box> <textElement/> <textFieldExpression><![CDATA[$F{field}]]></textFieldExpression> </textField> In iReport you can use “Padding And Borders” … Read more

Jasper Reports Show “Page X of Y” using a single text field

Jaspersoft Studio, 6+ For Jaspersoft Studio v6, or if the first page number is duplicated, try this solution, which uses $V{MASTER_CURRENT_PAGE} and $V{MASTER_TOTAL_PAGE} with an evaluation time of Master. Jaspersoft Studio For other versions of Jaspersoft Studio, try the steps outlined in the subsequent subsections. Create Variable Create a variable as follows: Create a variable … Read more

How to pass main report data source to subreport (JasperReports)?

You can pass datasource via the built-in REPORT_DATA_SOURCE parameter. The example: <subreport> <reportElement x=”261″ y=”25″ width=”200″ height=”100″/> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + “subreport.jasper”]]></subreportExpression> </subreport> You can create new instance of datasource based on variable, parameter or field. The sample: <variable name=”HeadingsCollection” class=”java.util.Collection” calculation=”System”> <initialValueExpression><![CDATA[new java.util.ArrayList()]]></initialValueExpression> </variable> … <subreport> <reportElement x=”0″ y=”0″ width=”515″ height=”20″/> <subreportParameter name=”ReportTitle”> <subreportParameterExpression><![CDATA[$P{ReportTitle}]]></subreportParameterExpression> </subreportParameter> … Read more