JSReport document generation API
The JsReportDocumentGenerator
utility class in Brightspot simplifies the process of generating documents using JSReport. This utility class provides two distinct methods, catering to different use cases, allowing developers to seamlessly integrate JSReport document generation within their Brightspot projects. This topic describes each method and its use cases.
createDocument(String template, Object data)
Creates a Document
for the specified JSReport template and input data.
- Parameters:
template
: The JSReport template to use, specified by either the template name or short ID.data
: The data used to render the JSReport template, typically represented as ajava.util.Map
to convey JSON data.
- Return:
- A
Document
object containing the document produced by JSReport, including the document's content and content type.
- A
Usage example
String templateName = "myTemplate";
Map<String, Object> jsonData = // ... prepare JSON data
Document generatedDocument = JsReportDocumentGenerator.createDocument(templateName, jsonData);
createDocument(String template, Class dateEntryView, Object content)
Creates a Document
using the specified template, dateEntryView
, and content
, leveraging the Brightspot view system.
- Parameters:
template
: The entry view used to find an appropriate view model. If null, theDefaultJsReportTemplate
annotation will be checked for a default template.dateEntryView
: The entry view used to find an appropriate view model.content
: The content providing data for document generation.
- Return:
- A
Document
object containing the document produced by JSReport, including the document's content and content type.
- A
Usage example
Object content = Query.from(MyRecord.class).first(); // contrived example for getting cotent from BSP DB
Document generatedDocument = JsReportDocumentGenerator.createDocument(null, JsReportViewModel.class, content);
@JsonView
@ViewInterface
@DefaultJsReportTemplate("myPdf")
public class JsReportViewModel extends ViewModel<MyRecord> {
public String getTitle() {
return model.getHeadline();
}
public String getCompany() {
return model.getCompany();
}
}
-
Specifies that the ViewModel can be converted to JSON, which is the primary format JSReport accepts.
-
Specifies that the ViewModel is a ViewInterface, meaning any public getter methods are included in data.
-
Specifies that the default JSReport template to use for this viewmodel has the name "myPdf". This will be used in the API call from line #2 since a null value was passed for the template parameter.
-
Marks this class as a ViewModel for the "MyRecord" class.
-
This will result in a "title" key in the resulting JSON passed to JSReport.
-
This will result in a "company" key in the resulting JSON passed to JSReport.
Previous Topic
Configuring the JSReport integration
Next Topic
Enabling JSReport preview