Mail Merge on Template Document using Java List & POJO Objects Data Source | Execute With Table Regions

I have a requirement to use mailmerge to produce a document that contains customer data including a list of related “alerts”. This data is in the form of business objects, pojo’s.

So I have a Customer object with e.g. String variables of name, address and a typed List of Alert objects. I have made a class extending IMailMergeDataSource that handles in its “getValue()” requests for fieldName of “name”, “Address” and “alerts”, setting the appropriate result into fieldValue.

I have a template document with MailMerge field names for “name” and “address” and a TableStart:alerts and TableEnd:alerts inside a table row.

When I execute getMailMerge().execute() I get all the static fields fine - e.g. name and address - but the alerts table doesn’t get processed. When I execute getMailMerge().executeWithRegions I get nothing. None of the static fields and none of the Table fields are processed.

How should I be setting this up? I’m going in circles…

Thanks in advance

@rouppe,

Have you also tried the latest (20.7) version of Aspose.Words for Java on your end? In case the problem still remains, please ZIP and attach the following resources here for testing:

  • Your simplified template Word document
  • Aspose.Words 20.7 generated DOCX file showing the undesired behavior
  • A standalone simple Java application (source code without compilation errors) that helps us to reproduce/observe this problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.
  • Any other necessary resources required to reproduce the issue on our end.

As soon as you get these pieces of information ready, we will start further investigation into your scenario and provide you more information.

Hi and thanks for the reply. I have attached MailMerge.zip to show the problem.

PoiPojo, Alert and PoiList are the business objects. They are inflated by unmarshalling POI.xml. PoiMailMergeDataSource implements IMailMergeDataSource in order to access the business object data. The template document used standard mailmerge fields, and (tries to) implement TableStart directives for the list.

Everything works fine (using getMailMerge().execute()) until I want to show a list of Alert data. I’m not getting either a getValue or getChildDataSource request. Thinking I needed to use regions to process a list I changes execute() to executeWithRegions() but that didn’t output any data into the template.

Thanks again, AndrewMailMerge.zip (18.7 KB)

@rouppe,

I am afraid, the Java compiler on our end gives a few compile time errors and is unable to recognize following:

import lombok.Getter;
// Unable to resolve following methods in getValue function of PoiMailMergeDataSource class:
getName 
getAddress
getAddressType
getAddressVerified
getDob
...
...
getAlerts

Can you please fix these problems and provide a standalone simple Java application (source code without compilation errors) that helps us to reproduce/observe this problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.