I want to implement custom DataSource in Java
DataSource dataSource=dao.getTemplateData();
DataSourceMailMerge dataSourceMailMerge=new DataSourceMailMerge(dataSource); doc.getMailMerge().execute(dataSourceMailMerge);
How to implement DataSourceMailMerge class:-
Example below…
Class DataSourceMailMerge implements IMailMergeDataSource {
DataSource dataSource;
public DataSourceMailMerge(DataSource dataSource) {
this.dataSource=dataSource;
}
@Override
public String getTableName() throws Exception {
return "DatSource";
}
@Override
public boolean moveNext() throws Exception {
return false;
}
@Override
public boolean getValue(String fieldName, Ref<Object> fieldValue) throws Exception {
String value= String.valueOf(fieldValue.get());
switch (fieldName)
{
case "FullName":
value= dataSource.cName;
return true;
case "Address":
value = dataSource.addressLine1;
return true;
default:
fieldValue = null;
return false;
}
}
@Override
public IMailMergeDataSource getChildDataSource(String s) throws Exception {
return null;
}