Showing posts with label JASPER REPORT. Show all posts
Showing posts with label JASPER REPORT. Show all posts

Thursday, May 13, 2021

19 - net sf jasperreports engine JRException Error retrieving field valu...

18 - Generate PDF with Jasperreport and Spring Boot SOLVED


In this tutorial, I show you how to generate a PDF with Jasperreport and Spring Boot .
application.properties:
   
 spring.datasource.url=jdbc:mysql://localhost:3306/YOURDATABASE?autoReconnect=true
spring.datasource.username=YOURUSERNAME
spring.datasource.password=YOURPASSWORD
spring.jpa.generate-ddl=true
	
   
  
POM.xml:
   



		<dependency>
    		<groupId>net.sf.jasperreports</groupId>
    		<artifactId>jasperreports</artifactId>
    		<version>6.16.0</version>
		</dependency>
		<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency> 
		
   
  
Main Java Class:
  
  package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServiceJpasql001Application {

	public static void main(String[] args) {
		SpringApplication.run(ServiceJpasql001Application.class, args);
	}

}

  
Student Class:
  
  
  package com.example.demo.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="student")
public class Student{
 
	@Id
    @Column(name="stid")
	private int stid;
	
    @Column(name="name")
	private String name;
    
    @Column(name="programme")
	private String Programme;

	public int getStid() {
		return stid;
	}

	public void setStid(int stid) {
		this.stid = stid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProgramme() {
		return Programme;
	}

	public void setProgramme(String programme) {
		Programme = programme;
	}

	public Student(int stid, String name, String programme) {
		super();
		this.stid = stid;
		this.name = name;
		Programme = programme;
	}

	public Student() {
		super();
		// TODO Auto-generated constructor stub
	}
	  
}
  
  
StudentRepository :
  
  
  package com.example.demo.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.demo.model.Student;

public interface StudentRepository extends JpaRepository {
  	List findByName(String name);
}
  
  
StudentService:
  
  
  package com.example.demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.model.Student;
import com.example.demo.repository.StudentRepository;

@Service
public class StudentService {

	@Autowired
	private StudentRepository studentRepository;
	
	public Student addStudent(Student student) {
		
		return studentRepository.save(student);
	}
	
	
  public void deleteStudent(Student student) {
		
		 studentRepository.delete(student);
	}
  
	public List getStudent() {
		
		return studentRepository.findAll();
	}
	
    public List getStudentByName(String name) {
		
		return studentRepository.findByName(name);
	}
}
  
  
StudentController:
  
  
  package com.example.demo.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.model.Student;
import com.example.demo.service.StudentService;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;

@RestController
public class StudentController {

	
	@Autowired
	StudentService studentService;
	
	@RequestMapping("/all")
	public List getStudent() {		
		return studentService.getStudent();
	}
	
	@RequestMapping("/studentByName/{name}")
	public List getStudentByName(@PathVariable String name) {		
		return studentService.getStudentByName(name);
	}
	
	@RequestMapping("/save")
	public  Student  saveStudent(@RequestBody Student student) {		
		return studentService.addStudent(student);
	}
	
	@RequestMapping("/delete")
	public  void  deleteStudent(@RequestBody Student student) {		
		 studentService.deleteStudent(student);
	}
	
	
	@RequestMapping("/pdf")
	
	  public void getReportsinPDF(HttpServletResponse response) throws JRException, IOException {
	    	
		 //Compiled report
		InputStream jasperStream = (InputStream) this.getClass().getResourceAsStream("/StudentList.jasper");
	      
	    //Adding attribute names
	    Map params = new HashMap<>();
	    params.put("stid","stid");
	    params.put("name","name");
	    params.put("programme","programme");
	    
	   // Fetching the student from the data database.
        final JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(studentService.getStudent());
        
	    JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperStream);
	    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, source);

	    response.setContentType("application/x-pdf");
	    response.setHeader("Content-disposition", "inline; filename=StudentList.pdf");

	    final ServletOutputStream outStream = response.getOutputStream();
	    JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);
	  }
}

  
  

Dev Tips#64 Connect Jaspersoft Studio to a JDBC Database Data Adapter li...

Friday, May 29, 2020

Dev Tips#43 Connect MYSQL to a Jasper report in Java and JDBC

In this tutorial, I show you how to retrieve data from MySQL to a Jasper Report in Java. JDBC is used to get an instance of the connection and passed to the jasper report engine...
Settings.xml:
   
    <mirrors>
        <mirror>
      <id>mirror1</id>
      <mirrorOf>central</mirrorOf>
      <name>mirror1</name>
      <url>https://repo.maven.apache.org/maven2/</url>
        </mirror>
    </mirrors>
   
  
POM.xml:
   
<dependencies>
        <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.8.0</version>
    <type>jar</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <artifactId>commons-collections</artifactId>
            <groupId>commons-collections</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-beanutils</artifactId>
            <groupId>commons-beanutils</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-digester</artifactId>
            <groupId>commons-digester</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
</dependency>
    </dependencies>
   
  
Main Java Class:
  package com.mycompany.mavenprojectdemov1;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader; 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
 
/**
 * Hello world!
 *
 */
public class App 
{
        
    public static Connection getDbaseConnection(String HOST_NAME, String DBASE_NAME,
        String USER_NAME, String USR_PASS) throws SQLException,
        ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        //String connectionURL = "jdbc:mysql://" + hostName + ":3306/" + dbName;
        String CNTION_URL = "jdbc:mysql://" + HOST_NAME + "/" + DBASE_NAME;
        Connection conn = DriverManager.getConnection(CNTION_URL, USER_NAME,USR_PASS);
        return conn;
    }
    
    public static void main( String[] args )
    {
        //Database credential
        String hostName = "localhost";
        String dbName = "springboot";
        String userName = "springboot";
        String password = "springboot";
        
        //Jasper file location
        String fileNameJrxml = "E:/Jasper/jasperv1.jrxml";
        String fileNamePdf = "E:/Jasper/jasperv1.pdf";
 
        try {
            //Getting a connection instance
            Connection connInstance = getDbaseConnection(hostName,dbName,userName,password);                   
            System.out.println("Loading the .JRMXML file ....");
            JasperDesign jasperDesign = JRXmlLoader.load(fileNameJrxml);
            System.out.println("Compiling the .JRMXML file to .JASPER file....");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            System.out.println("filling parameters to .JASPER file....");
            JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperReport, null,connInstance);
            System.out.println("exporting the JASPER file to PDF file....");
            JasperExportManager.exportReportToPdfFile(jprint, fileNamePdf);
            System.out.println("Successfully completed the export");

        } catch (Exception e) {
            System.out.print("Exception:" + e);
        }

    }
}


  

Wednesday, May 27, 2020

Dev Tips#42 Passing parameters to a Jasper Report in Java

In this tutorial, I show you how to pass parameteres to a Jasper report in JAVA running in Netbeans IDE 8.
Settings.xml:
   
    <mirrors>
        <mirror>
      <id>mirror1</id>
      <mirrorOf>central</mirrorOf>
      <name>mirror1</name>
      <url>https://repo.maven.apache.org/maven2/</url>
        </mirror>
    </mirrors>
   
  
POM.xml:
   
<dependencies>
        <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.8.0</version>
    <type>jar</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <artifactId>commons-collections</artifactId>
            <groupId>commons-collections</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-beanutils</artifactId>
            <groupId>commons-beanutils</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-digester</artifactId>
            <groupId>commons-digester</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>
    </dependencies>
   
  
Main Java Class:
 package com.mycompany.mavenprojectdemov1;

import java.util.HashMap;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader; 
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
      

        String fileNameJrxml = "E:/Jasper/Blank_A4_Paramv2.jrxml";
        String fileNamePdf = "E:/Jasper/Blank_A4_Paramv2.pdf";
 
        try {
            System.out.println("Loading the .JRMXML file ....");
            JasperDesign jasperDesign = JRXmlLoader.load(fileNameJrxml);
            System.out.println("Compiling the .JRMXML file to .JASPER file....");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            String first_language = "Java";
            String second_language = "Structured text";
            HashMap hm = new HashMap();
            hm.put("Param_First_Language", first_language);
            hm.put("Param_Second_Language", second_language);
            System.out.println("filling parameters to .JASPER file....");
            JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperReport, hm, new JREmptyDataSource());
            System.out.println("exporting the JASPER file to PDF file....");
            JasperExportManager.exportReportToPdfFile(jprint, fileNamePdf);
            System.out.println("Successfully completed the export");

        } catch (Exception e) {
            System.out.print("Exception:" + e);
        }

    }
}

  

Friday, May 22, 2020

Dev Tips#39 Jasper report in Java 8 and Netbeans 8

In this video I show you how to create a jasper report in Java 8 and Netbeans 8 with dependencies handled by maven to export a PDF. How to export a PDF in java.




Settings.xml:




  

    <mirrors>
        <mirror>
            <id>mirror1</id>
            <mirrorOf>central</mirrorOf>
            <name>mirror1</name>
            <url>https://repo.maven.apache.org/maven2</url>   
        </mirror>
    </mirrors>

  
  


Dependencies:




  

    <dependencies>
        <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.8.0</version>
    <type>jar</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <artifactId>commons-collections</artifactId>
            <groupId>commons-collections</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-beanutils</artifactId>
            <groupId>commons-beanutils</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-digester</artifactId>
            <groupId>commons-digester</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.8.0</version>
</dependency>
    </dependencies>

  
  


Java code:




  
package com.mycompany.mavenprojectdemov1;

import java.util.HashMap;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader; 
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
      

        String fileNameJrxml = "E:/Jasper/HelloPDF.jrxml"; 
        String fileNamePdf = "E:/Jasper/HelloPDFv2.pdf";
 
        try {
            System.out.println("Loading the .JRMXML file ....");
            JasperDesign jasperDesign = JRXmlLoader.load(fileNameJrxml);
            System.out.println("Compiling the .JRMXML file to .JASPER file....");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            HashMap hm = new HashMap();
            System.out.println("filling parameters to .JASPER file....");
            JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperReport, hm, new JREmptyDataSource());
            System.out.println("exporting the JASPER file to PDF file....");
            JasperExportManager.exportReportToPdfFile(jprint, fileNamePdf);
            System.out.println("Successfully completed the export");

        } catch (Exception e) {
            System.out.print("Exception:" + e);
        }

    }
}

  




Sunday, May 17, 2020

Dev Tips#37 Create your first Jasper report in Java and VS code maven


In this tutorial, I show you how to create a simple jasper report with a static text in TIBCO Jasper Report Studio. Then run the jrmxl file in a Maven Java Project in visual studio code to get a pdf.

Main Class


   

package com.abc;
import java.util.HashMap;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader; 
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
      

        String fileNameJrxml = "E:/Jasper/HelloPDF.jrxml";
        String fileNamePdf = "E:/Jasper/HelloPDF.pdf";
 
        try {
            System.out.println("Loading the .JRMXML file ....");
            JasperDesign jasperDesign = JRXmlLoader.load(fileNameJrxml);
            System.out.println("Compiling the .JRMXML file to .JASPER file....");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            HashMap hm = new HashMap();
            System.out.println("filling parameters to .JASPER file....");
            JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperReport, hm, new JREmptyDataSource());
            System.out.println("exporting the JASPER file to PDF file....");
            JasperExportManager.exportReportToPdfFile(jprint, fileNamePdf);
            System.out.println("Successfully completed the export");

        } catch (Exception e) {
            System.out.print("Exception:" + e);
        }

    }
}


  
  


List of dependencies for the pom.xml
    

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.8.0</version>
</dependency>
  <dependency>
   <groupId>commons-beanutils</groupId>
   <artifactId>commons-beanutils</artifactId>
   <version>1.9.3</version>
   <scope>compile</scope>
   <optional>false</optional>
  </dependency>
  <dependency>
   <groupId>commons-digester</groupId>
   <artifactId>commons-digester</artifactId>
   <version>2.1</version>
   <scope>compile</scope>
   <optional>false</optional>
  </dependency>
  <dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.1.1</version>
   <scope>compile</scope>
   <optional>false</optional>
  </dependency>
  <dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-collections4</artifactId>
   <version>4.2</version>
   <scope>compile</scope>
   <optional>false</optional>
  </dependency>
    <dependency>
   <groupId>com.lowagie</groupId>
   <artifactId>itext</artifactId>
   <version>2.1.7.js6</version>
    <scope>compile</scope>
   <optional>false</optional>
   <exclusions>
    <exclusion>
     <groupId>org.bouncycastle</groupId>
     <artifactId>bcmail-jdk15on</artifactId>
    </exclusion>
    <exclusion>
     <groupId>org.bouncycastle</groupId>
     <artifactId>bcpkix-jdk15on</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
 <dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi</artifactId>
   <version>4.0.1</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi-ooxml</artifactId>
   <version>4.0.1</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
<dependency>
   <groupId>org.eclipse.jdt.core.compiler</groupId>
   <artifactId>ecj</artifactId>
   <version>4.4.2</version>
   <scope>compile</scope>
   <optional>false</optional>
  </dependency>
  <dependency>
   <groupId>org.codehaus.groovy</groupId>
   <artifactId>groovy-all</artifactId>
   <version>2.4.5</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
    <dependency>
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-core</artifactId>
   <version>2.8.2</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-jcl</artifactId>
   <version>2.8.2</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>net.sf.jasperreports</groupId>
   <artifactId>jasperreports-fonts</artifactId>
   <version>6.8.0</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.apache.lucene</groupId>
   <artifactId>lucene-core</artifactId>
   <version>7.3.0</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.apache.lucene</groupId>
   <artifactId>lucene-analyzers-common</artifactId>
   <version>7.3.0</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.apache.lucene</groupId>
   <artifactId>lucene-queryparser</artifactId>
   <version>7.3.0</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.olap4j</groupId>
   <artifactId>olap4j</artifactId>
   <version>0.9.7.309-JS-3</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
    <dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-pool2</artifactId>
   <version>2.4.2</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
   <version>1.5</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>net.sf.jasperreports</groupId>
   <artifactId>jasperreports-metadata</artifactId>
   <version>6.8.0</version>
   <scope>compile</scope>
   <optional>true</optional>
  </dependency>

  </dependencies> 

  
  


Thursday, January 30, 2014

Location of Jars in ireport

Many tend to be confused about the location of  jars libraries in jasper ireport. In fact for the case of Microsoft Windows, after the installation yours jars will reside inside the following location:

C:\Program Files\Jaspersoft\iReport-XXX\ireport\modules\ext


Friday, January 10, 2014

Getting a org.springframework.beans.factory.BeanCreationException with my first Maven, Spring Project

If you are getting this error message, you maybe missing a crucial jar file in your project. Just download the spring- jar include it to your project, build it and move forward.

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

Facing this problem can be very painful, I have been and lost a couple of my precious hours trying to dig it out. I won't talk much because it is not my field of predilection. I am pragmatic and let us go straight to the point.
Solution:
You have download two jars and include in your project.
  1. commons-javaflow
  2. spring- jar
Hopefully you have include them, build your project and regain your smiling face. Happy coding day though  !!!

Wednesday, January 8, 2014

Conditional expression in ireport

Expression condition for the first in ireport for many usually seems awkward given that we have to leave behind our programming legacy of  IF ELSE and do it another way.

And here come the issue, suppose we have to define the following condition :

IF boolean condition THEN
 
     execute true code snippet
 
 ELSE
 
    execute false code snippet
 
 END IF
 
Ireport we will otherwise do it as follow:
 
 
( boolean condition ? execute true code snippet : execute false code snippet)
 
e.g:
 
if ( conVar > 0 )
     binVar= 1
 
else binVar= -1
 
Then becomes:
 
 (conVar > 0 ? binVar= 1: binVar=-1)

 
It the similar way we can express some complicated and nested conditions.
If you still face any problems feel free to drop a comment. 

Thursday, November 7, 2013

Irepot: Row transferred to next page get Calculated in the current page

This is a common problem with ireport but no formal ansvwer yet but some  workarounds do exist and I will show you one.

Here is the problem:  I have a report with a numeric column(suppose its name is quantity) per row which I want to show summation of that column for all records in every page, the desired value will calculate from summation of quantity columns in current page and all previous pages(suppose its name is qSum). If i allow splitting for Detail band rows, there is no problem, but when I prevent splitting, the quantity column value of splitted row will add to calculated summation (qSum) of current page, but the row itself will shown in the next page!
In order words how can I force the summation to be only for the row appearing on that page. (excluding the transferred row)
My column summation is the column footer.

Workaround: the key thing to do here is to create a dummy group for each row based on their primary key.

How ?

Whenever a row spread over two consecutives pages ireport becomes confused. Instead of using split type= prevent as option in the detail band , set it to split type= Stretch. Then create a dummy group (by primary key of the row) with group header and footer enabled that will act as a container for each row . Dummy group option are: reprint header=true, Min Height to start new= value of detail band height, Footer Position= normal, Keep together= true.

Now if each is processed as group and will be forwarded to next page it cannot fit a the current one. This scenario is common with financial accounting report when you have credit , debit and has to calculate a running balance with carry forward and bring forward totals.

I will try on my next post to illustrate this solution with some screenshots, but for now I hope you have got some ideas at least. Feel free to comment or knock me.  

Thursday, September 19, 2013

Control line spacing in ireport

Is it possible to control the line spacing in ireport ? Yes

I have recently come through this problem during one of project as the requirement was to have something line the following
 but what I had by defaut in ireport is


The question is How to reach my target of reducing line spacing ?

This is easily achievable in ireport (version 5.00 ) . In fact ireport offer various properties for controlling line
  spacing . If you click on a textfield and go to properites you get the following options
 line spacing has many options available :
  •  single (default)
  • 1.5
  • Double
  • At least 
  • Fixed 
  • Proportional
If you set it to fixed , you can control line spacing by entering different value in line spacing size .
For the remaining option s, you can easily test them yourself.

Note:
I assume you can insert a newline in ireport , if not here is how you can do that using \n.
As in the preceding example , we want to insert four (04) fields in a single textfield and each appearing in a newline.

$F{empName}+"\n\n"+$F{comment1}+"\n"+$F{comment2}+"\n"+$F{comment3}

Hope you find it useful.


Wednesday, December 26, 2012

Leading zeroes formatting ireport

Hi, welcome to my blog. Are you having problem formatting leading zeroes in jasper ireport
for example:

1--->001
 10-->010

Steps:
1.Right clikc the textfield -->field pattern --->put the number of zero corresponding to the number of digit you want.
2. For the above example , I have three digits so I should put  000
3. Rock it !!!!!!!!!


Monday, September 17, 2012

Jasper report: column footer not appearing directly below detail band

Maybe you wanted the column footer to appear directly below the detail band without success.
Certainly this tips may help you.
1.Go to designer view ---> Report inspector -->right click report name --->properties-->Check "Float column Footer".
2.Go back to design view --->set the height of summary band to zero or just delete it.
3. Rock your world.

Thursday, July 19, 2012

Ireport : forward a broken row to the new page

Suppose a row height is so long that it is spread on two pages.
Using this option will do the job
<columnHeader>
        <band height="20" splitType="Prevent">
            <staticText>
</staticText>
        </band>
    </columnHeader>
<detail>
        <band height="18" splitType="Prevent">
            <textField isStretchWithOverflow="true" isBlankWhenNull="false">
                .....
            </textField>
</detail>