Showing posts with label DynamicReport. Show all posts
Showing posts with label DynamicReport. Show all posts

Monday, January 12, 2015

DynamicReports: Add a line in front of / after a sub report condittionally

The following code demonstrate how to add an horizontal line before a subreport only when the subreport is not null or only when it has data.


import java.util.ArrayList;
import java.util.List;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.base.expression.AbstractSimpleExpression;
import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.definition.ReportParameters;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class PageSubreportTest {
    public static void main(String[] args){
        new PageSubreportTest();
    }
 
    public PageSubreportTest() {
        JasperReportBuilder report = build();
        try {
            report.show();
        }catch (DRException e){
            e.printStackTrace();
        }
    }
 
    private JasperReportBuilder build() {
        JasperReportBuilder report = report();
        report.setDataSource(createDataSource());
     
        SubreportBuilder storeSubreport = cmp.subreport(buildStoreSubReport())
                .setDataSource(exp.subDatasourceBeanCollection("storeData"));
        SubreportBuilder fruitSubreport = cmp.subreport(buildFruitSubReport())
                .setDataSource(exp.subDatasourceBeanCollection("fruitData"));
     
        report.detail(cmp.horizontalList(cmp.horizontalGap(50),storeSubreport, cmp.horizontalGap(50)),
                cmp.verticalGap(15),
             
                //To add a horizontal line only when fruitSubreport has data
                cmp.line().setPen(stl.pen1Point())
                        .setPrintWhenExpression(new LinePrintExpression()),
             
                cmp.verticalGap(15),
             
                fruitSubreport,
                cmp.verticalGap(15),
                //To add a horizontal line only when fruitSubreport has data
                cmp.line().setPen(stl.pen1Point())
                        .setPrintWhenExpression(new LinePrintExpression()));
     
        report.title(cmp.text("Fuit Stores Report")
            .setStyle(stl.style().bold()
                    .setHorizontalAlignment(HorizontalAlignment.CENTER)));
        report.pageFooter(cmp.pageXofY());
     
        return report;
    }
 
    private class LinePrintExpression extends AbstractSimpleExpression<Boolean> {
        public Boolean evaluate(ReportParameters param){
            List<FruitData> list = param.getValue("fruitData");
            if (list == null || list.isEmpty()){
                return false;
            } else {
                return true;
            }
        }
    }
 
    private JasperReportBuilder buildStoreSubReport(){
        JasperReportBuilder storeReport = report();
        storeReport.columns(col.column("", "storeInfo", DataTypes.stringType()));
     
        return storeReport;
    }
 
    private JasperReportBuilder buildFruitSubReport(){
        JasperReportBuilder fruitReport = report();
        fruitReport.columns(col.column("Name", "fruitName", DataTypes.stringType()),
                col.column("Price", "fruitPrice", DataTypes.doubleType())
                    .setPattern("$#,###,##0.00")
                    .setHorizontalAlignment(HorizontalAlignment.LEFT),
                col.column("Description", "des", DataTypes.stringType()));
     
        fruitReport.setColumnTitleStyle(stl.style().bold());
        return fruitReport;
    }
 
    private JRBeanCollectionDataSource createDataSource() {
        List<ReportData> dataSource = new ArrayList<ReportData>();

        ReportData data = new ReportData();
        List<StoreData> storeList = new ArrayList<StoreData>();
        List<FruitData> fruitList = new ArrayList<FruitData>();
        //first set of data
        StoreData storeData = new StoreData();
        storeData.setStoreInfo("Delicious Fruit");
        storeList.add(storeData);
        storeData = new StoreData();
        storeData.setStoreInfo("554 Main Street, Burlington, MN 33596");
        storeList.add(storeData);
        data.setStoreData(storeList);

        FruitData fruitData = new FruitData();
        fruitData.setFruitName("Apple");
        fruitData.setFruitPrice(1.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        fruitData = new FruitData();
        fruitData.setFruitName("Orange");
        fruitData.setFruitPrice(0.98d);
        fruitData.setDes("Very juicy");
        fruitList.add(fruitData);
        data.setFruitData(fruitList);
        dataSource.add(data);

        //second set of data
        data = new ReportData();
        storeList = new ArrayList<StoreData>();
//        fruitList = new ArrayList<FruitData>();

        storeData = new StoreData();
        storeData.setStoreInfo("Fruit Outlet");
        storeList.add(storeData);
        storeData = new StoreData();
        storeData.setStoreInfo("99 Uphill Ave., Rochester, MN 33596");
        storeList.add(storeData);
        data.setStoreData(storeList);
//        data.setFruitData(fruitList);
        dataSource.add(data);

        //Third set of data
        data = new ReportData();
        storeList = new ArrayList<StoreData>();
        fruitList = new ArrayList<FruitData>();
     
        storeData = new StoreData();
        storeData.setStoreInfo("Fruit Depot");
        storeList.add(storeData);
        storeData = new StoreData();
        storeData.setStoreInfo("233 Park Viewers Ave., Bay East, FL 33596");
        storeList.add(storeData);
        data.setStoreData(storeList);
     
        fruitData = new FruitData();
        fruitData.setFruitName("Papaya");
        fruitData.setFruitPrice(2.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        fruitData = new FruitData();
        fruitData.setFruitName("Mango");
        fruitData.setFruitPrice(3.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        data.setFruitData(fruitList);
        dataSource.add(data);

        return new JRBeanCollectionDataSource(dataSource);
    }
 
    public class ReportData {
        private List<StoreData> storeData;
        private List<FruitData> fruitData;
     
        public List<StoreData> getStoreData() { return storeData; }
        public void setStoreData(List<StoreData> s) { storeData = s; }
        public List<FruitData> getFruitData() { return fruitData; }
        public void setFruitData (List<FruitData> s) { fruitData = s; }
    }
 
    public class StoreData {
        private String storeInfo;
     
        public String getStoreInfo() { return storeInfo; }
        public void setStoreInfo(String s) { storeInfo = s; }
    }
 
    public class FruitData {
        private String fruitName;
        private Double fruitPrice;
        private String des;
     
        public String getFruitName() { return fruitName; }
        public void setFruitName(String s) { fruitName = s; }
        public Double getFruitPrice() { return fruitPrice; }
        public void setFruitPrice(Double s) { fruitPrice = s; }
        public String getDes() { return des; }
        public void setDes(String s) { des = s; }
    }
}
         
---------------------------------------------------------------------------------------------------------------------
                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Friday, October 17, 2014

DynamicReport: Setting font name, size and style for report, column, text component and subreport


JasperReportBuilder report = DynamicReports.report();

1. The default font for the whole report.

          report.setDefaultFont(stl.font("<font name>", isBold, isItalic, fontSize ));

          //Or
          // report.setDefaultFont(stl.fontArial().setFontSize(9));
          // report.setDefaultFont(stl.font().boldItalic());
          // report.setDefaultFont(stl.font().setUnderline(true));

2. Font for a column

           report.columns(col.column("Name", type.stringType())
                     .setStyle(stl.style().setFont(stl.font("<font name>", isBold, isItalic, fontSize ))));

           //Or
           // TextColumnBuilder clmn = col.column("Name", type.stringType());
           // clmn.setStyle(stl.style().setFontSize(9).bold().italic());
           //report.addColumn(clmn);

4. Font for a text component

           cmp.text("<your text>").setStyle(stl.style().setFont(stl.font("<font name>", isBold, isItalic, fontSize )));

5. Font for a sub-report

            SubreportBuilder subreport = <your sub-report>;
            subreport.setStyle(stl.style().setFont(stl.font("<font name>", isBold, isItalic, fontSize )));

---------------------------------------------------------------------------------------------------------      

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Wednesday, October 8, 2014

DynamicReports: How to make subreport display at a fixed page position / bottom of last page - resolved

Lets say that you have a subreport which displays a message. The length of the message can be from 0 to 20 lines. Following this message subreport, you have another subreport which displays some data and you would like it to be always displayed at the bottom one third of the page regardless the length of the message.

One way to make the second data subreport to be always displayed at a certain height of the page is to set the height of the first message subreport above it. The way to do it is to put the subreport in a vertical list or a horizontal list and set the height/width/dimension of that vertical list or horizontal list.

However, if the message has so many lines that it overflows the space you specified, the message subreport will expand and push your data subreport down. If this happens and you would like the data subreport to be displayed at the bottom one third of the next page, you need to count the lines of your message and need to know how many lines of message the space you specified can hold and the whole page can hold. If the lines of message is larger than the lines of message your space can hold, you need to add empty lines to the message until it starts to display on the next page. You need to let it display at least one line on the next page, only then the height you specified for the message subreport will apply to the message on the next page and let your data subreport be displayed at the right position.


import java.util.ArrayList;
import java.util.List;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class ReportDimensionDemo {
    private int messageRows = 0;

    public static void main(String[] args){
        new ReportDimensionDemo();
    }
 
    public ReportDimensionDemo() {
        JasperReportBuilder report = DynamicReports.report();
        report.setDataSource(createDataSource());
     
        SubreportBuilder messageSubreport = cmp.subreport(buildMessageSubreport())
                .setDataSource(exp.subDatasourceBeanCollection("messageData"));
        SubreportBuilder dataSubreport = cmp.subreport(buildDataSubreport())
                .setDataSource(exp.subDatasourceBeanCollection("dataData"));
     
        report.detail(cmp.verticalList(messageSubreport).setFixedHeight(300),
               // .setFixedWidth(200)
                //.setFixedDimension(200, 300)
                dataSubreport );
       //to display at the bottom of last page
       //report.summary(dataSubreport);      
        try {
            report.show(false);
        }catch(DRException de){
            de.printStackTrace(System.out);
        }
    }
 
    private JasperReportBuilder buildMessageSubreport() {
        JasperReportBuilder report = DynamicReports.report();
        report.columns(col.column("message", DataTypes.stringType()));
     
        return report;
    }
 
    private JasperReportBuilder buildDataSubreport() {
        JasperReportBuilder report = DynamicReports.report();
        report.columns(col.column("Name", "name", DataTypes.stringType())
                    .setStyle(stl.style(stl.pen1Point())),
                col.column("Price", "price", DataTypes.doubleType())
                        .setStyle(stl.style(stl.pen1Point()))
                        .setPattern("$##0.00"));
     
        return report;
    }
 
    private JRDataSource createDataSource() {
        List<ReportData> dataSource = new ArrayList<ReportData>();
        ReportData reportData = new ReportData();
        List<MessageData> messageList = new ArrayList<MessageData>();
        MessageData messageData = new MessageData();
        List<DataData> dataList = new ArrayList<DataData>();
        DataData dataData = new DataData();
     
        for (i=0; i<50; i++) {
             messageData.setMessage("The most useful report in the universe - "+i);
             messageList.add(messageData);
             //count the lines of message
             messageRows++;
             messageData = new MessageData();
        }

        //If the message overflow the height you specified, push the message band
        //to the next page so that the data subreport is displayed at the right
         //position on the next page.
        int remainder = messageRows%<message lines per whole page>
        if (remainder > <message lines in specified space>) {
              while (remainder < (<message lines per whole page> + 2)) {
                      messageData.setMessage("");
                      messageList.add(messageData);
                      messageData = new MessageData();
              }
       }
     
        reportData.setMessageData(messageList);
     
        dataData.setName("Apple");
        dataData.setPrice(1.68);
        dataList.add(dataData);
        dataData = new DataData();
        dataData.setName("Papaya");
        dataData.setPrice(3.14);
        dataList.add(dataData);
        reportData.setDataData(dataList);
     
        dataSource.add(reportData);
        return new JRBeanCollectionDataSource(dataSource);
    }
 
    public class ReportData {
        private List<MessageData> messageData;
        private List<DataData> dataData;
     
        public List<MessageData> getMessageData() {return messageData;}
        public void setMessageData(List<MessageData> m) {messageData=m;}
        public List<DataData> getDataData() {return dataData;}
        public void setDataData(List<DataData> d) {dataData=d;}
    }
 
    public class MessageData{
        private String message;
     
        public String getMessage() {return message;}
        public void setMessage(String m) {message=m;}
    }
 
    public class DataData {
        private String name;
        private Double price;
     
        public String getName() {return name;}
        public void setName(String n) {name=n;}
        public Double getPrice() {return price;}
        public void setPrice(Double p) {price=p;}
    }
}
   
----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Tuesday, September 23, 2014

DynamicReports: How to set the height/width/dimension of a sub-report?

Lets say that you have a subreport which displays a message. The length of the message can be from 0 to 20 lines. Following this message subreport, you have another subreport which displays some data and you would like it to be always displayed at the bottom one third of the page regardless the length of the message.

One way to make the second data subreport to be always displayed at a certain height of the page is to set the height of the first message subreport above it. The way to do it is to put the subreport in a vertical list or a horizontal list and set the height/width/dimension of that vertical list or horizontal list.


import java.util.ArrayList;
import java.util.List;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class ReportDimensionDemo {
    public static void main(String[] args){
        new ReportDimensionDemo();
    }
 
    public ReportDimensionDemo() {
        JasperReportBuilder report = DynamicReports.report();
        report.setDataSource(createDataSource());
     
        SubreportBuilder messageSubreport = cmp.subreport(buildMessageSubreport())
                .setDataSource(exp.subDatasourceBeanCollection("messageData"));
        SubreportBuilder dataSubreport = cmp.subreport(buildDataSubreport())
                .setDataSource(exp.subDatasourceBeanCollection("dataData"));
     
        report.detail(cmp.verticalList(messageSubreport).setFixedHeight(300),
               // .setFixedWidth(200)
                //.setFixedDimension(200, 300)
                dataSubreport );
        try {
            report.show(false);
        }catch(DRException de){
            de.printStackTrace(System.out);
        }
    }
 
    private JasperReportBuilder buildMessageSubreport() {
        JasperReportBuilder report = DynamicReports.report();
        report.columns(col.column("message", DataTypes.stringType()));
     
        return report;
    }
 
    private JasperReportBuilder buildDataSubreport() {
        JasperReportBuilder report = DynamicReports.report();
        report.columns(col.column("Name", "name", DataTypes.stringType())
                    .setStyle(stl.style(stl.pen1Point())),
                col.column("Price", "price", DataTypes.doubleType())
                        .setStyle(stl.style(stl.pen1Point()))
                        .setPattern("$##0.00"));
     
        return report;
    }
 
    private JRDataSource createDataSource() {
        List<ReportData> dataSource = new ArrayList<ReportData>();
        ReportData reportData = new ReportData();
        List<MessageData> messageList = new ArrayList<MessageData>();
        MessageData messageData = new MessageData();
        List<DataData> dataList = new ArrayList<DataData>();
        DataData dataData = new DataData();
     
        messageData.setMessage("The most useful report in the universe.");
        messageList.add(messageData);
        reportData.setMessageData(messageList);
     
        dataData.setName("Apple");
        dataData.setPrice(1.68);
        dataList.add(dataData);
        dataData = new DataData();
        dataData.setName("Papaya");
        dataData.setPrice(3.14);
        dataList.add(dataData);
        reportData.setDataData(dataList);
     
        dataSource.add(reportData);
        return new JRBeanCollectionDataSource(dataSource);
    }
 
    public class ReportData {
        private List<MessageData> messageData;
        private List<DataData> dataData;
     
        public List<MessageData> getMessageData() {return messageData;}
        public void setMessageData(List<MessageData> m) {messageData=m;}
        public List<DataData> getDataData() {return dataData;}
        public void setDataData(List<DataData> d) {dataData=d;}
    }
 
    public class MessageData{
        private String message;
     
        public String getMessage() {return message;}
        public void setMessage(String m) {message=m;}
    }
 
    public class DataData {
        private String name;
        private Double price;
     
        public String getName() {return name;}
        public void setName(String n) {name=n;}
        public Double getPrice() {return price;}
        public void setPrice(Double p) {price=p;}
    }
}
   
-----------------------------------------------------------------------------------------------------------  

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Friday, August 22, 2014

net.sf.dynamicreports.report.exception.DRException: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 1. java.lang.ClassNotFoundException: [L;

The following code throws such an exception. The line of code that causes the exception is marked in yellow. The reason that this exception occurs is that the program uses a list of beans instead an array of beans to hold the data of the subreport. Therefore, to fix this problem, you just need to change the "exp.subDatasourceBeanArray" to "exp.subDatasourceBeanCollection" in the marked code below.

import java.util.ArrayList;
import java.util.List;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.constant.StretchType;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class PageSubreportTest {
    public static void main(String[] args){
        new PageSubreportTest();
    }
 
    public PageSubreportTest() {
        JasperReportBuilder report = build();
        try {
            report.show();
        }catch (DRException e){
            e.printStackTrace();
        }
    }
 
    private JasperReportBuilder build() {
        JasperReportBuilder report = report();
        report.setDataSource(createDataSource());
     
        SubreportBuilder storeSubreport = cmp.subreport(buildStoreSubReport())
                .setDataSource(exp.subDatasourceBeanCollection("storeData"));
        SubreportBuilder fruitSubreport = cmp.subreport(buildFruitSubReport())
                .setDataSource(exp.subDatasourceBeanArray("fruitData"));
     
        report.detail(cmp.horizontalList(cmp.horizontalGap(50),storeSubreport, cmp.horizontalGap(50)),
                cmp.verticalGap(15),
                //To set the border for the fruitSubreport
                //put it in a horizontallist and then set the border
                cmp.horizontalList(fruitSubreport)
                        .setStretchType(StretchType.RELATIVE_TO_TALLEST_OBJECT)
                        .setStyle(stl.style().setBorder(stl.pen1Point())));
                //For page subreport, set the page break at the end.
//                cmp.pageBreak());
        report.title(cmp.text("Fuit Stores Report")
            .setStyle(stl.style().bold()
                    .setHorizontalAlignment(HorizontalAlignment.CENTER)));
        report.pageFooter(cmp.pageXofY());
     
        return report;
    }
 
    private JasperReportBuilder buildStoreSubReport(){
        JasperReportBuilder storeReport = report();
        storeReport.columns(col.column("", "storeInfo", DataTypes.stringType()));
     
        return storeReport;
    }
 
    private JasperReportBuilder buildFruitSubReport(){
        JasperReportBuilder fruitReport = report();
        fruitReport.columns(col.column("Name", "fruitName", DataTypes.stringType()),
                col.column("Price", "fruitPrice", DataTypes.doubleType())
                    .setPattern("$#,###,##0.00")
                    .setHorizontalAlignment(HorizontalAlignment.LEFT),
                col.column("Description", "des", DataTypes.stringType()));
     
        fruitReport.setColumnTitleStyle(stl.style().bold());
        return fruitReport;
    }
 
    private JRBeanCollectionDataSource createDataSource() {
        List<ReportData> dataSource = new ArrayList<ReportData>();

        ReportData data = new ReportData();
        List<StoreData> storeList = new ArrayList<StoreData>();
        List<FruitData> fruitList = new ArrayList<FruitData>();
        //first set of data
        StoreData storeData = new StoreData();
        storeData.setStoreInfo("Delicious Fruit");
        storeList.add(storeData);
        storeData = new StoreData();
        storeData.setStoreInfo("554 Main Street, Burlington, MN 33596");
        storeList.add(storeData);
        data.setStoreData(storeList);

        FruitData fruitData = new FruitData();
        fruitData.setFruitName("Apple");
        fruitData.setFruitPrice(1.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        fruitData = new FruitData();
        fruitData.setFruitName("Orange");
        fruitData.setFruitPrice(0.98d);
        fruitData.setDes("Very juicy");
        fruitList.add(fruitData);
        data.setFruitData(fruitList);
        dataSource.add(data);

        //second set of data
        data = new ReportData();
        storeList = new ArrayList<StoreData>();
        fruitList = new ArrayList<FruitData>();

        storeData = new StoreData();
        storeData.setStoreInfo("Fruit Outlet");
        storeList.add(storeData);
        storeData = new StoreData();
        storeData.setStoreInfo("99 Uphill Ave., Rochester, MN 33596");
        storeList.add(storeData);
        data.setStoreData(storeList);

        fruitData = new FruitData();
        fruitData.setFruitName("Papaya");
        fruitData.setFruitPrice(2.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        fruitData = new FruitData();
        fruitData.setFruitName("Mango");
        fruitData.setFruitPrice(3.98d);
        fruitData.setDes("Medium juicy");
        fruitList.add(fruitData);
        data.setFruitData(fruitList);
        dataSource.add(data);

        return new JRBeanCollectionDataSource(dataSource);
    }
 
    public class ReportData {
        private List<StoreData> storeData;
        private List<FruitData> fruitData;
     
        public List<StoreData> getStoreData() { return storeData; }
        public void setStoreData(List<StoreData> s) { storeData = s; }
        public List<FruitData> getFruitData() { return fruitData; }
        public void setFruitData (List<FruitData> s) { fruitData = s; }
    }
 
    public class StoreData {
        private String storeInfo;
     
        public String getStoreInfo() { return storeInfo; }
        public void setStoreInfo(String s) { storeInfo = s; }
    }
 
    public class FruitData {
        private String fruitName;
        private Double fruitPrice;
        private String des;
     
        public String getFruitName() { return fruitName; }
        public void setFruitName(String s) { fruitName = s; }
        public Double getFruitPrice() { return fruitPrice; }
        public void setFruitPrice(Double s) { fruitPrice = s; }
        public String getDes() { return des; }
        public void setDes(String s) { des = s; }
    }
}

------------------------------------------------------------------------------------------------------------      

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Thursday, August 21, 2014

DynamicReports Page subreport - create subreport in a page of the parent report and set report/subreport/component border

One way to create a page with different subreports is to list the subreports in the detail of the report and add a page break at the end of the list.

To create a border of a subreport, you can put the subreport in a HorizontalList or a VerticalList and add a border to this component.

import java.util.ArrayList;
import java.util.List;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.constant.StretchType;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class PageSubreportTest {
    public static void main(String[] args){
        new PageSubreportTest();
    }
 
    public PageSubreportTest() {
        JasperReportBuilder report = build();
        try {
            report.show();
        }catch (DRException e){
            e.printStackTrace();
        }
    }
 
    private JasperReportBuilder build() {
        JasperReportBuilder report = report();
        report.setDataSource(createDataSource());
     
        SubreportBuilder storeSubreport = cmp.subreport(buildStoreSubReport())
                .setDataSource(exp.subDatasourceBeanCollection("storeData"));
        SubreportBuilder fruitSubreport = cmp.subreport(buildFruitSubReport())
                .setDataSource(exp.subDatasourceBeanCollection("fruitData"));
     
        report.detail(cmp.horizontalList(cmp.horizontalGap(50),storeSubreport, cmp.horizontalGap(50)),
                cmp.verticalGap(15),
                //To set the border for the fruitSubreport
                //put it in a horizontallist and then set the border
                cmp.horizontalList(fruitSubreport)
                        .setStretchType(StretchType.RELATIVE_TO_TALLEST_OBJECT)
                        .setStyle(stl.style().setBorder(stl.pen1Point())),
                //For page subreport, set the page break at the end.
                //Otherwise, it will become detail subreport.
              cmp.pageBreak());
        report.title(cmp.text("Fuit Stores Report")
            .setStyle(stl.style().bold()
                    .setHorizontalAlignment(HorizontalAlignment.CENTER)));
        report.pageFooter(cmp.pageXofY());
     
        return report;
    }
 
    private JasperReportBuilder buildStoreSubReport(){
        JasperReportBuilder storeReport = report();
        storeReport.columns(col.column("", "storeInfo", DataTypes.stringType()));
     
        return storeReport;
    }
 
    private JasperReportBuilder buildFruitSubReport(){
        JasperReportBuilder fruitReport = report();
        fruitReport.columns(col.column("Name", "fruitName", DataTypes.stringType()),
                col.column("Price", "fruitPrice", DataTypes.doubleType())
                    .setPattern("$#,###,##0.00")
                    .setHorizontalAlignment(HorizontalAlignment.LEFT),
                col.column("Description", "des", DataTypes.stringType()));
     
        fruitReport.setColumnTitleStyle(stl.style().bold());
        return fruitReport;
    }
 
    private JRBeanCollectionDataSource createDataSource() {
            List<ReportData> dataSource = new ArrayList<ReportData>();
     
            ReportData data = new ReportData();
            List<StoreData> storeList = new ArrayList<StoreData>();
            List<FruitData> fruitList = new ArrayList<FruitData>();

            //first set of data
            StoreData storeData = new StoreData();
            storeData.setStoreInfo("Delicious Fruit");
            storeList.add(storeData);
            storeData = new StoreData();
            storeData.setStoreInfo("554 Main Street, Burlington, MN 33596");
            storeList.add(storeData);
            data.setStoreData(storeList);
         
            FruitData fruitData = new FruitData();
            fruitData.setFruitName("Apple");
            fruitData.setFruitPrice(1.98d);
            fruitData.setDes("Medium juicy");
            fruitList.add(fruitData);
            fruitData = new FruitData();
            fruitData.setFruitName("Orange");
            fruitData.setFruitPrice(0.98d);
            fruitData.setDes("Very juicy");
            fruitList.add(fruitData);
            data.setFruitData(fruitList);
            dataSource.add(data);
         
            //second set of data
            data = new ReportData();
            storeList = new ArrayList<StoreData>();
            fruitList = new ArrayList<FruitData>();
         
            storeData = new StoreData();
            storeData.setStoreInfo("Fruit Outlet");
            storeList.add(storeData);
            storeData = new StoreData();
            storeData.setStoreInfo("99 Uphill Ave., Rochester, MN 33596");
            storeList.add(storeData);
            data.setStoreData(storeList);
         
            fruitData = new FruitData();
            fruitData.setFruitName("Papaya");
            fruitData.setFruitPrice(2.98d);
            fruitData.setDes("Medium juicy");
            fruitList.add(fruitData);
            fruitData = new FruitData();
            fruitData.setFruitName("Mango");
            fruitData.setFruitPrice(3.98d);
            fruitData.setDes("Medium juicy");
            fruitList.add(fruitData);
            data.setFruitData(fruitList);
            dataSource.add(data);
           
            return new JRBeanCollectionDataSource(dataSource);
    }
 
    public class ReportData {
        private List<StoreData> storeData;
        private List<FruitData> fruitData;
     
        public List<StoreData> getStoreData() { return storeData; }
        public void setStoreData(List<StoreData> s) { storeData = s; }
        public List<FruitData> getFruitData() { return fruitData; }
        public void setFruitData (List<FruitData> s) { fruitData = s; }
    }
 
    public class StoreData {
        private String storeInfo;
     
        public String getStoreInfo() { return storeInfo; }
        public void setStoreInfo(String s) { storeInfo = s; }
    }
 
    public class FruitData {
        private String fruitName;
        private Double fruitPrice;
        private String des;
     
        public String getFruitName() { return fruitName; }
        public void setFruitName(String s) { fruitName = s; }
        public Double getFruitPrice() { return fruitPrice; }
        public void setFruitPrice(Double s) { fruitPrice = s; }
        public String getDes() { return des; }
        public void setDes(String s) { des = s; }
    }
}

           Previous <
       
-----------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

References:
1. DynamicReports: Row Subreport - create a subreport in each row of the parent report
2. DynamicReports: Column Subreport - create subreport in a column of the parent report

Thursday, July 24, 2014

net.sf.dynamicreports.report.exception.DRException: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean

The stack trace of the exception has the following lines.

net.sf.dynamicreports.report.exception.DRException: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean

Caused by: java.lang.NoSuchMethodException: Property '<bean property>' has no getter method in class

The following code throws such an exception.

public class DynamicReportsTest {
         public DynamicReportsTest() {
                  build();
         }

         private void build() {
                   JasperReportBuilder report = DynamicReports.report();
                   report.columns(col.column("Name", "name", DataTypes.stringType()),
                            col.column("Price", "price", DataTypes.doubleType()));

                    report.dataDataSource(createDataSource());
                    report.show();
         }

         private JRBeanCollectionDataSource createDataSource() {
                   List<ReportData> dataSource = new ArrayList<ReportData>();
                   ReportData data = new ReportData();

                   data.setName("Apple");
                   data.setPrice(1.89d);

                   dataSource.add(data);
                   data = new ReportData();    
                  data.setName("Papaya");
                   data.setPrice(2.35d);

                   dataSource.add(data)

                   return new JRBeanCollectionDataSource(dataSource);
          }
     
         private class ReportData {
                   private String name;
                   private double price;

                   public String getName() {
                             return name;
                   }
                   public void setName(String n) {
                            name = n;
                   }
                   public double getPrice() {
                             return price;
                   }
                   public void setPrice(double p) {
                            price = p;
                   }
         }

          public static void main(String[] args) {
                     new DynamicReportsTest();
          }
}

When the program is laying out the report, the data source is accessed by other code to retrieve the data. Since the ReportData class is private, its methods is invisible to other code.

To fix the exception simply change the ReportData inner class to public.

           public class ReportData{
                      . . . . . .
           }
       
----------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

DynamicReports set the title, zoom ratio, page fit to frame width of JasperViewer

When report.show() is called, the JasperViewer will display your report on the screen. By default, the title of the JasperViewer is "JasperViewer", and the zoom ratio is 100%. Follwing is some sample code for setting the title of the JasperViewer and setting the zoom ratio of the report to allow it to fit the width of the frame.

JasperReportBuilder report = DynamicReports.report();
report.columns(col.column("Column 1", "col1", DataTypes.stringType(),
                        . . . . . .
                       );
report.setDataSource(<dataSource>);

//Create the JasperViewer frame
JasperViewer reportViewer = new JasperViewer(report.toJasperPrint(), false);
//Without the second boolean argument, parent frame closes when the JasperViewer is closed
//JasperViewer reportViewer = new JasperViewer(report.toJasperPrint();

//Set the title to your choice
reportViewer.setTitle("<your title>");

//Set the zoom ratio, here it is 110%
//reportViewer.setZoomRatio(new Float(1.10));

//The page fit frame width zoom ration is 89.49%
reportViewer.setZoomRatio(new Float(0.8949)); //the frame fit ratio

reportViewer.setVisible(true);
       
---------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Wednesday, July 16, 2014

DynamicReports: DRDataSource, JRBeanCollectionDataSource, and JRMapCollectionDataSource

There are several ways to create data source for a Dynamic Report.

1. DRDataSource

          This is the most straightforward one. You create a DRDataSource with a list of the field names of the columns in the report. You then add data row by row to the data source.

         //The fieldNames here must be the same as in the report columns
         DRDataSource dataSource = new DRDataSource("fieldName1', "fieldName2", ....);

         //Add a row of values corresponding to the fields listed above
         dataSource.add(value1, value2, value3......);

         report.setDataSource(dataSource);

2. JRBeanCollectionDataSource

          You need a Bean class to hold each row of the data in your report. This class must be public even though it is most likely an inner class. Otherwise a method not available error may occur.

            //Create the bean
            public class ReportData {
                    //the data type and field name must be the same as the corresponding column in the report
                    private String fieldName1;
                    private Integer fieldName2;

                    ............

                   //getters and setters for all the fields
                   public String getFieldName1() {
                           return fieldName1
                   }
                   public void setFieldName1(String f1) {
                           fieldName1 = f1;
                   }

                  .............
           }

           //Create a Collection of the Bean with your data
           List<ReportData> sourceData = new ArrayList<ReportData>();
           ReportData data = new ReportData();
     
           for (i=0; i<5; i++) {
                     data.setFieldName1("field one value");
                     data.setFieldName2(49);

                     ............

                     sourceData.add(data);
                     data = new ReportData();
           }

           //Create the data source
           JRDataSource dataSource = new JRBeanCollectionDataSource(sourceData);
           report.setDataSource(dataSource);

3. JRMapCollectionDataSource

        You need a map to hold each row of the data in your report. The key is the fieldName of a column and value is your data.

         //Create a Collection of the Map
         List<Map<String, Object>> sourceData = new ArrayList<Map<String, Objec>>();
         Map<String, Object> data = new HashMap<String, Object>();

        for (int i=0; i<5; i++) {
                 data.put("fieldName1", "field one value");
                 data.put("filedName2", 49);

                ...........

                sourceData.add(data);
                data = new HashMap<String, Object>();
        }

        //Create the data source
         JRDataSource dataSource = new JRMapCollectionDataSource(sourceData);
         report.setDataSource(dataSource);

--------------------------------------------------------------------------------------------------------
         
                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
   
       
          

DynamicReports: Row Subreport - create a subreport in each row of the parent report

Assume that you have two tables, Fruit and Sales, in your database.

Table Fruit
name            price         popularIndex           freshDays
Apple           1.68         10                           20
Orange         0,96         5                             8

Table Sales
saleDate            fruitName        amount         customer            charge        payment           balance
01/02/2013       Apple              1000            uphill fruit store  1680           1680               0
05/12/2014       Orange            2000            delicious            1920           1000               920

Now, you would like to have a report to list all the data in the Fruit table, and under each fruit list 10 of the most recent sales

Following is a sample code for creating the report.

public class FruitReportTest {
          private JasperReport buildFruitReport() {
                     JasperReportBuilder report = DynamicReports.report();
                     report.columns(col.column("Name", "name", type.stringType()),
                                 col.column("Price", "price", type.doubleType()),
                                 col.columns("Popular Index", "popIndx", type.integerType()),
                                 col.columns("Fresh Days", "freshDays", type.integerType()));
                    return report;
          }

           private JasperReportBuilder buildSalesReport() {
                     JasperReportBuilder report = DynamicReports.report();
                     report.columns(col.column("Sale Date", "saleDate", type.stringType()),
                                 col.column("Amount", "amount", type.doubleType()),
                                 col.columns("Customer", "customer", type.stringType()),
                                 col.columns("Charge", "charge", type.doubleType()),
                                 col.columns("Payment", "payment", type.doubleType()),
                                 col.columns("Balance", "balance", type.doubleType()));
                   return report;
           }

           public class ReportData {
                    private String name;
                    private Double price;
                    private Integer popIndx;
                    private Integer freshDays;
                    private List<Map<String, Object>> salesData;
           
                    //getters and setters for all the above fields
                    .............
          }

          private JRDataSource createDataSource() {
                    Connection conn = <your method of getting database connection>
                    String sql1 = "Select * from Fruit";
                    PreparedStatement ps1 = conn.prepareStatement(sql1);
                    ResultSet rs = ps1.executeQuery();

                    String sql2 = "select * from Sales where fruitName = ?";
                    preparedStatement ps2 = conn.prepareStatement(sql2)

                    List<ReportData> datasource = new ArrayList<ReportData>();
                    try {
                               while (rs.next()) {
                                           ReportData data = new ReportData();
                                           data.setName(rs.getString(1));
                                           data.setPrice(rs.getDouble(2));
                                           data.setPopIndx(rs.getInt(3));
                                           data.setFreshDays(rs.getInt(4));

                                          ps2.setString(1, rs.getString(1));
                                          ResultSet rs2 = ps2.executeQuery();
                                       
                                          List<Map<String, Object>> salesData = new ArrayList<Map<String, Object>>();
                                         Map<String, Object> sd = new HashMap<String, Object>();
                                        while (rs2.next()){
                                                  ds.put("saleDate", rs2.getString(1));
                                                  ds.put("amount", rs2.getDouble(3));
                                                  ds.put("customer", rs2.getString(4));
                                                  ds.put("charge", rs2.getDouble(5));
                                                  ds.put("payment", rs2.getDouble(6));
                                                  ds.put("balance", rs2.getDouble(7));

                                                 salesData.add(ds);
                                       }
                                       data.setSalesData(salesData);
                                       rs2.close();    
                               }
                               ps2.close();
                               rs.close();
                               ps1.close();
                    } catch (SQLException se) {
                                 se.printStackTrace();
                    }
                    conn.close();

                    return new JRBeanCollectionDataSource(datasource);
          }

       

         public static void main(String[] args) {
                    FruitReportTest test = new FruitReportTest();

                    JasperReportBuilder report = test.buildFruitReport();

                    SubreportBuilder subreport = cmp.subreport(test.buildSalesReport())
                          .setDataSource(exp.subDatasourceBeanCollection("salesData"));
                   report.detailFooter(cmp.horizontalList(cmp.horizontalGap(10), subreport, cmp.horizontalGap(10)));

                   report.setDataSource(createDataSource());
                   report.show();
         }
}

          Previous <                     > Next
       

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


Reference:

1. DynamicReports: Column Subreport - create subreport in a column of the parent report
2. DynamicReports Page subreport - create subreport in a page of the parent report and set report/subreport/component border

Tuesday, July 8, 2014

DynamicReports: Column Subreport - create subreport in a column of the parent report

Following is a sample code of creating a subreport that includes the name and price in the parent column Objects.

import static net.sf.dynamicreports.report.builder.DynamicReports.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.base.expression.AbstractSimpleExpression;
import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.component.SubreportBuilder;
import net.sf.dynamicreports.report.builder.style.Styles;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.definition.ReportParameters;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.data.JRMapCollectionDataSource;

public class ColumnSubreportTest {

    public ColumnSubreportTest() {
        SubreportBuilder subreport = cmp.subreport(new SubreportDesign())
                .setDataSource(new SubreportData());
     
        JasperReportBuilder report = DynamicReports.report();
        try {
            report.fields(field("objects", List.class))
                    .columns(
                            col.column("Category", "category", type.stringType()),
                            col.column("Health Index", "healthIndex", type.integerType()),
                            col.componentColumn("Objects", subreport)
                            .setFixedWidth(240)
                            .setStyle(Styles.style()
                                    .setBottomPadding(15))
                            .setTitleStyle(Styles.style()
                                    .bold().setHorizontalAlignment(HorizontalAlignment.LEFT)));
            report.setColumnTitleStyle(Styles.style().bold()
                    .setHorizontalAlignment(HorizontalAlignment.LEFT));
            report.setColumnStyle(Styles.style()
                    .setHorizontalAlignment(HorizontalAlignment.LEFT));
            report.title(cmp.text("List of real food")
                    .setStyle(Styles.style().bold().setFontSize(14)
                            .setHorizontalAlignment(HorizontalAlignment.CENTER)
                            .setBottomPadding(20)))
                    .pageFooter(Templates.footerComponent);

            report.setDataSource(createDataSource());
            report.show();
        } catch (DRException e) {
            e.printStackTrace();
        }
   }

   private class SubreportDesign extends AbstractSimpleExpression<JasperReportBuilder> {
      private static final long serialVersionUID = 1L;

      @Override
      public JasperReportBuilder evaluate(ReportParameters reportParameters) {
         JasperReportBuilder report = report()
            .columns(col.column("name", type.stringType()),
                    col.column("price", type.stringType()));
         return report;
      }
   }

   private class SubreportData extends AbstractSimpleExpression<JRDataSource> {

      @Override
      public JRDataSource evaluate(ReportParameters reportParameters) {
         Collection<Map<String, ?>> value = reportParameters.getValue("objects");
         return new JRMapCollectionDataSource(value);
      }
   }

  private JRDataSource createDataSource() {
   ArrayList<ReportData> datasource = new ArrayList<ReportData>();

   ReportData data = new ReportData();
   data.setCategory("Fruit");
   data.setHealthIndex(95);
 
   List<Map<String, Object>> objects = new ArrayList<Map<String, Object>>();
   Map<String, Object> values = new HashMap<String, Object>();
   values.put("name", "Apple");
   values.put("price", "$1.65/lb");
   objects.add(values);
   values = new HashMap<String, Object>();
   values.put("name", "Papaya");
   values.put("price", "$1.98/lb");
   objects.add(values);
   data.setObjects(objects);
 
   datasource.add(data);
 
   data = new ReportData();
   data.setCategory("Rice");
   data.setHealthIndex(70);
 
   objects = new ArrayList<Map<String, Object>>();
   values = new HashMap<String, Object>();
   values.put("name", "Brown Rice");
   values.put("price", "$0.35/lb");
   objects.add(values);
   values = new HashMap<String, Object>();
   values.put("name", "White Rice");
   values.put("price", "$0.15/lb");
   objects.add(values);
   data.setObjects(objects);
 
   datasource.add(data);

      return new JRBeanCollectionDataSource(datasource);
   }

   //It is important to let this inner class to be public
   public class ReportData {
      private String category;
      private Integer hi;
      private List<Map<String, Object>> objects;

      public String getCategory() {
         return category;
      }

      public void setCategory(String c) {
         category = c;
      }

      public Integer getHealthIndex() {
         return hi;
      }

      public void setHealthIndex(Integer i) {
         hi = i;
      }

      public List<Map<String, Object>> getObjects() {
         return objects;
      }

      public void setObjects(List<Map<String, Object>> o) {
         objects = o;
      }
   }

   public static void main(String[] args) {
      new ColumnSubreportTest();
   }
}

                             > Next
       
------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
----------------------------------------------------------------------------------------------------------------------

References:

1. Row Subreport - create subreport in a row of the parent report
2. DynamicReports Page subreport - create subreport in a page of the parent report and set report/subreport/component border