Kismiss reports is designed for simpify both development and report design. Although kismiss cannot cover the complex report design, it can be used to solve most wanted design report. For complex report, Ireport is the best solution to use.
The first thing we need is including the kismiss required libraries in application, shown like below :
.
+ lib
commons-beanutils.jar
commons-collections.jar (3.1 above)
commons-deigester.jar
commons-lang.jar (2.3 above)
commons-logging.jar
itext.jar (2.0.2 above)
jasperreports.jar (3.0.0 above)
jdt-compiler.jar
log4j.jar
poi.jar
slf4j-api.jar
slf4j-log4j.jar
velocity.jar
The application that using kismiss need to include minimum libraries required shown above. Include all that libraries to your application. (Actually, Log4j is not required but preferred by many developers.)
Simple Kismiss Reports
First Kismiss Report
This section, we will create our first kismiss report. First, we need to create JavaBean class and define properties there. In this example, we will create a “Employee.java” class, then generate it's report by informations and data given. Let's see “Employee.java” as shown below :
package com.softtech.kismiss.main;
import com.softtech.kismiss.enumer.CalculationPrintType;
import com.softtech.kismiss.enumer.HorizontalAlignment;
import com.softtech.kismiss.enumer.PaperType;
import com.softtech.kismiss.enumer.VerticalAlignment;
import com.softtech.kismiss.property.Detail;
import com.softtech.kismiss.property.FieldGroup;
import com.softtech.kismiss.property.Group;
import com.softtech.kismiss.property.Header;
import com.softtech.kismiss.property.Kismiss;
import com.softtech.kismiss.property.Property;
/**
* @author Kisman Hong
* test Kismiss Reports
*/
@Kismiss(name = "Employee", columnAutoSize = true, paperType = PaperType.A4, isTitleEveryPage=false)
@Header(columnHeaderHeight=25, isColumnHeaderBold=true, columnHeaderColor="#CCCCCC", lineWidth=0.5)
@Group(calculation = {"salary : Sum", "capacity : Average"}, groupBy="division", calculationPrintType=CalculationPrintType.Complete, horizontalAlignment = HorizontalAlignment.Right)
@Detail(lineWidth=0.5)
public class Employee {
private Integer id;
@FieldGroup
private String lastName;
@FieldGroup
private String firstName;
@FieldGroup(label="ALAMAK")
private String address;
@FieldGroup
private String phoneNumber;
@FieldGroup
private String postCode;
private String division;
private Double salary;
private Integer capacity;
private Person person;
@Property( width = 45, position = 5, verticalAlignment=VerticalAlignment.Top, isShowInDetail=false)
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
@Property(width = 45, position = 6, horizontalAlignment = HorizontalAlignment.Right, fontSize=6, verticalAlignment= VerticalAlignment.Middle)
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Property(name = "Post Code", width = 50, position = 7)
public String getPostCode() {
return postCode;
}
public void setPostCode(String postCode) {
this.postCode = postCode;
}
@Property(name = "Address", width = 100, position = 3, fontSize=6)
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Property(name = "First Name", width = 100, position = 1, columnHierarchy="Name info", heightPortion=15)
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Property(name = "Last Name", width = 100, position = 2, columnHierarchy="Name info", heightPortion=15)
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Property(name="No", width=30, isRecordNumber=true, position=0)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Property(name = "Salary", width = 45, position = 4, horizontalAlignment = HorizontalAlignment.Center, fontSize=6)
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
@Property(width = 35, position = 8, horizontalAlignment = HorizontalAlignment.Center, fontSize=6, verticalAlignment=VerticalAlignment.Middle)
public Integer getCapacity() {
return capacity;
}
public void setCapacity(Integer capacity) {
this.capacity = capacity;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
You can see that this class uses standard JavaBean naming conventions for property getter and setter methods, as well as private visibility for the fields. This is a recommended design.
Kismiss-reports properties are defined at JavaBean class. Let's see “Employee.java” for more detail :
Kismiss and Header are defined at the top of the class. Attribute name of Kismiss is required.
Property is defined at the getter method. (Kismiss choose the getter method for defining property to prevent too many annotations at the fields). Property is used for defining field, width and position are required.
Now, we will write some java code to fill the report data and generate Employee report :
List<Employee> employees = new ArrayList<Employee>();
for(int i=0; i < 1000; i++)
{
Employee employee = new Employee();
String[] name = produceName();
employee.setAddress("California Rd. No. 143, Jakarta Barat");
employee.setDivision("Kalem Kalem");
employee.setFirstName(name[0]);
employee.setLastName(name[1]);
employee.setPhoneNumber(producePhone());
employee.setPostCode(producePostCode());
employee.setSalary(produceSalary());
employee.setCapacity(9);
employees.add(employee);
}
for(int i=0; i < 1000; i++)
{
Employee employee = new Employee();
String[] name = produceName();
employee.setAddress("Last Vegas Rd. No. 341, Jakarta Timur");
employee.setDivision("Hura Hura");
employee.setFirstName(name[0]);
employee.setLastName(name[1]);
employee.setPhoneNumber(producePhone());
employee.setPostCode(producePostCode());
employee.setSalary(produceSalary());
employee.setCapacity(5);
employees.add(employee);
}
KismissReport report = KismissReport.getInstance();
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(ReportFactory.TITLE, "TEST KISMISS REPORT");
params.put(ReportFactory.INFOTITLE, "Report");
params.put(ReportFactory.PDF_NAME, "employeeTest.pdf");
report.generateAnnotatedPdfFiles(Employee.class, employees, "D:/Personal/Test/", params);
Let us see step by step :
initialize kismiss report instance
declare the report params to be included
defining title of report
give report file name
generate report
The code above is quite simple. We do not need a long code to generate the report. Prepare the data then call the generate method function.
The generateAnnotatedPdfFiles method has four parameters :
the JavaBean class that will be generated, in this example : “Employee.class”.
collection data of class, this is the content of report.
path where the pdf file will be generated.
the params of report, such as title, report file name, etc.
After finishing the following steps above, let us see the report result :
Kismiss Report will be released in 2011, a full reference documentation will be included.