The serializeDataElements class is used to serialize XML
data by setting values of all DDEs, PH, and Field elements. The
Generate a Letter PDF API consumes this serialized XML to render
the letter. This process appends PH and Field data (provided as
maps) to the DDI (provided as XML). You can use this API to provide variable
and field values before rendering the letter. The values of DDEs
are described in this table:
DDE
|
Description
|
ddiDataAsXml
|
The DDI data as XML.
|
phValues
|
A map containing the variable name versus
its value.
|
fieldValues
|
A map containing the somExpr of Field versus
the value of the Field.
|
The serializeDataElements syntax is as follows:
public String serializeDataElementsToXML(String ddiDataAsXml,Map<String,Object> phValues,Map<String,Object> fieldValues)
{
String strInitialXmlName="D:\\ES4SetUpDoc\\RenderLetter\\initialXML.xml";
Map<String,List> letterMap=letterService.getLetterDataElements(letterObject.getId());
Map<String,Object> phValues= new HashMap<String, Object>();
Map<String,Object> fieldValues= new HashMap<String, Object>();
List<Field> fieldList=letterMap.get("Field");
List<Variable> variableList=letterMap.get("PH");
//Prepraing field map
for(int i=0;i<fieldList.size();i++){
System.out.println("Path=="+fieldList.get(i).getPath());
fieldValues.put(fieldList.get(i).getPath(), "field"+i);
}
//Prepraing value map
for(int i=0;i<variableList.size();i++){
System.out.println("Name=="+variableList.get(i).getName());
phValues.put(variableList.get(i).getName(), "Var"+i);
}
String strLetterXML= letterRenderService.serializeDataElementsToXML(getStringFromXml(strInitialXmlName), phValues, fieldValues);
PDFResponseType pdfResponseType = null;
pdfResponseType = letterRenderService.renderLetter(letterObject
.getId(), strLetterXML, true, false, true);
File OutputFile = new File("D:\\ES4SetUpDoc\\RenderLetter\\RenderLetterWithField.pdf");
OutputFile.delete();
if (OutputFile.createNewFile()) {
FileOutputStream fos = new FileOutputStream(OutputFile);
fos.write(pdfResponseType.getFile().getDocument());
fos.flush();
fos.close();
} else {
log("not created");
}
}
The XML data given to LetterRenderService.renderLetter() APIs
data has additional elements in following format, where values of
place holder variables and fields is provided.
<data-root>
...
<fields> <!--starting element for fields -->
<field name="field1">value1</field> <!-- field's display-name is field1 and its value is set to value1. -->
<field name="field2" somExpr="xfa[0].template[0].field2">value2</field> <!-- Attribute somexpr is optional and can be used when display name is not sufficient to identify field uniquely -->
...
</fields>
<variables> <!--starting element for place holder variables-->
<variable name="var1">value1</variable> <!-- variable name is var1 and its value is set to value1 -->
....
</variables>
</data-root>
The DDEs values are provided as part of XML data. The renderLetter() considers
values provided with XML data and if there is value available for
corresponding DDE/PH/Field then these values is set for these DDE/PH/Field.
All other values are resolved through Binding. The field/variable
binding is not considered if XML data is available for variables
or fields. For example, if a Field is bound to an unprotected data
dictionary, and the value for the Field is specified in the XML data,
then specified value is used for rendering. When no value is set
in the XML data,the values of variables/Fields are set using bindings
(if present) and empty in case of binding a "User". For example,
if a Variable is bound to unprotected data dictionary, and no value
specified in the XML data, the data dictionary value is used when
rendering letter.