Merge table row cells in Jasper Reports , using JRBeanCollectionDataSource?

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email with questions or issues requiring TIBCO review or response.

I need to merge cells with related information. I find that using "printRepeatedValues = false" is not appropriate. this expression does not concatenate the columns, but leaves them blank. In my opinion, I need something like 2 datasets. The first describes the strings for related information, and the second describes the details of related information.But I still do not understand how to add the second dataset to existing table and how to tell the second dataset that it refers to the first row of the first dataset, for example

Here is what I'm doing: Filling out the report comes from Java, through the code goes like this.

List<MyDataClass> datas = new ArrayList<>();
    MyDataClass data1 = new MyDataClass("AAA", "AAA details1", "AAA details2", "good", "AAA details3");
    MyDataClass data2 = new MyDataClass("AAA", "AAA details11", "AAA details22", "good", "AAA details33");
    MyDataClass data3 = new MyDataClass("CCC", "CCC details1", "CCC details2", "good", "CCC details3");
    datas.add(data1); datas.add(data2);datas.add(data3);
    JRBeanCollectionDataSource dataForReport = new JRBeanCollectionDataSource(datas);
    Map<String, Object> parametrs = new HashMap<String, Object>();
    parametrs.put("CollectionBeanParametr", dataForReport);

But it results blank rows

Result which need i add to Attachments.Any working example how to do it by using JRBeanCollectionDataSource might help.Thank you!

sashaspb09's picture
Joined: Aug 2 2020 - 10:40pm
Last seen: 5 months 4 weeks ago

1 Answer:



Hard to explain how it works,someoone helped me to figure out my issue.Things which i understand: To merge cells like here, in Java code need 2 Models, first model for merge cells, in this case related1 column and related2 column:

public class Model {
private String related1;
private String related2;
private List<DetailsDataObjects> detailsDataObjects;
//getters | setters|Constructors}
  public class DetailsDataObjects {
private String details1;
private String details2;
private String details3;
//getters|setters| constructors
public static void main(String[] args){
DetailsDataObjects detailsDataObject = new ReportDataObjects();
detailsDataObject.setDetails1("AAA detais");
detailsDataObject.setDetails2("AAA details2");
detailsDataObject.setDetails3("AAA details3");
 List<DetailsDataObjects> detailsDataObjects = Arrays.asList(detailsDataObject, detailsDataObject , detailsDataObject ....);
 Model model1 = new Model();
List<Model> models = Arrays.asList(model1);
 JRBeanCollectionDataSource itemsJRBean = new JRBeanCollectionDataSource(models);
        params.put("ItemDataSource", itemsJRBean);

At JasperStudio need create 2 tables with 2 datasets, first dataset explain : $P{ItemDataSource} , second dataset explain : new$F{detailsDataObjects})

sashaspb09's picture
Joined: Aug 2 2020 - 10:40pm
Last seen: 5 months 4 weeks ago