Data Export
File Starter supports three export modes:
- Export by template fields
- builds candidate fields from current model metadata
- defaults selected fields to the currently visible table columns
- lets the user change fields, file name, and sheet name
- generates
.xlsxworkbooks for front-end initiated exports
-
Export by file template
- uses an uploaded Excel template file with
{{ field }}placeholders - extracts variables from the template to determine which fields to query
- generates
.xlsxworkbooks by rendering the template with data
- uses an uploaded Excel template file with
-
Dynamic export
- exports without a template by providing fields and filters directly in the request
- Export for re-import (by import template)
- writes the records into an import template’s own workbook, to be edited and imported back through that template; see “5. Export for re-import (by import template)” below
Built-in export supports three scopes:
Selected Rowsuses the current toolbar bulk selection idsCurrent Pageuses the current page id snapshot, notpageNumber/pageSizereplayAll Filtered Datareuses currentfilters/orders/groupBy/aggFunctions/effectiveDate
Front-end export is limited to 100000 records for a single request; over-limit scopes are disabled instead of truncated.
ExportTemplate Configuration Table
| Field | Type | Default | Description |
|---|---|---|---|
fileName | String | null | Export file name |
sheetName | String | null | Sheet name |
modelName | String | null | Model name to export |
customFileTemplate | Boolean | null | If true, use file template export mode; otherwise use field template mode |
fileId | Long | null | Template file id (required when customFileTemplate = true) |
filters | Filters | null | Default filters |
orders | Orders | null | Default orders |
customHandler | String | null | Spring bean name for CustomExportHandler |
enableTranspose | Boolean | null | Whether to transpose output (not implemented in starter) |
ExportTemplateField Configuration Table
| Field | Type | Default | Description |
|---|---|---|---|
templateId | Long | null | ExportTemplate id |
fieldName | String | null | Model field name (supports cascaded fields like deptId.name) |
customHeader | String | null | Custom column header |
sequence | Integer | null | Field order in export |
ignored | Boolean | null | Whether to ignore the field in output |
Checked when saved
An export template is checked against its modelName when it is written, by the rules the export applies when it runs — FieldPaths in softa-orm, which states what the WHERE builder, the ORDER BY builder and the cascaded read accept:
modelNamemust be a model of the metadata;- every field of
filtersmust be able to stand in a WHERE: through to-one relations by a join, or a to-many one by a sub-query, ending on a stored field; - every field of
ordersmust be able to stand in an ORDER BY: through to-one relations only, ending on a stored field; - each column’s
fieldNamemust be readable: through to-one relations only, up to four levels — what the export resolves its headers and values with.
As for import templates, a field is checked when the write sets it, and moving a template to another model re-checks its filters, orders and the columns the write keeps.
Cascaded Field Export
All three export modes support cascaded field references using dotted-path syntax (e.g. deptId.name, deptId.companyId.code).
This allows exporting fields from related models through ManyToOne/OneToOne associations.
Syntax: {field1}.{field2} or {field1}.{field2}.{field3} (up to 4 levels of cascade)
How it works:
- The ORM layer creates dynamic virtual fields for dotted-path references (via
MetaField.createDynamicField). - The field is split into 2 parts: the root ManyToOne/OneToOne field and the remaining path.
- The related model is queried with the remaining path as expand fields.
- For 3+ levels, the process recurses:
deptId.companyId.code→ queryDeptwith fieldcompanyId.code→ queryCompanywith fieldcode. - The resolved value is stored in the row map with the full dotted key (e.g.
deptId.companyId.code). - The column header: a template column’s
customHeaderwhen set; otherwise — and for every column of a dynamic export, which has nocustomHeader— the label of each many-to-one on its path and then the field’s:deptId.nameisDepartment › Name,employeeId.departmentId.nameisEmployee › Department › Name. Under the last label alone, the columns of two relations onto one model (a manager’s and an HR partner’s employee code) would share a header. A one-to-one hop adds nothing:employeeProfileId.passTypeisPass Type, a field of the row’s own sub-record. One rule for both modes (ExportColumnHeaders); a column that must read otherwise — a fixed outside format’s — names its header incustomHeader.
Rules:
- Maximum cascade depth: 4 levels (
BaseConstant.CASCADE_LEVEL = 4). - Each intermediate field must be ManyToOne or OneToOne type.
- The last field must be a stored field (not dynamic/computed).
ConvertType.DISPLAYis used, so option fields show the itemlabeland relation fields showdisplayName.
Example — Template export with cascaded fields:
ExportTemplateField configuration:
fieldName: "name" customHeader: null sequence: 1
fieldName: "deptId.name" customHeader: "Department" sequence: 2
fieldName: "deptId.managerId.name" customHeader: null sequence: 3Result Excel columns: Name | Department | Department › Manager › Name
Example — Dynamic export with cascaded fields:
curl -X POST 'http://localhost:8080/export/dynamicExport?modelName=Employee' \
-H 'Content-Type: application/json' \
-d @- <<'JSON'
{
"fields": ["name", "deptId.name", "deptId.managerId.name"],
"filters": ["status", "=", "ACTIVE"],
"orders": ["name", "ASC"]
}
JSONResult Excel columns: Name | Department › Name | Department › Manager › Name
1. Export By Template Fields
- Configure ExportTemplate and ExportTemplateField
ExportTemplate key fields:
fileName,sheetName,modelNamefilters,orders,customHandler
ExportTemplateField key fields:
fieldName,customHeader,sequence,ignored
- Export by template
Endpoint:
POST /export/exportByTemplate?exportTemplateId={id}
Request body:
ExportParams(fields, filters, orders, agg, groupBy, limit, effectiveDate)
Example:
curl -X POST http://localhost:8080/export/exportByTemplate?exportTemplateId=2001 \
-H 'Content-Type: application/json' \
-d @- <<'JSON'
{
"fields": ["id", "name", "code", "status"],
"filters": ["status", "=", "ACTIVE"],
"orders": ["createdTime", "DESC"],
"limit": 200,
"groupBy": [],
"effectiveDate": "2026-03-03"
}
JSON2. Export By File Template (Upload Template File)
This mode uses an uploaded Excel template file with placeholders like {{ field }} or {{ object.field }}.
The system extracts variables from the template to decide which fields to query.
To use this mode, set customFileTemplate = true and fileId to the uploaded template file in ExportTemplate.
The same exportByTemplate endpoint is used; the system dispatches to file-template mode automatically based on the customFileTemplate flag.
Endpoint:
POST /export/exportByTemplate?exportTemplateId={id}
Example:
curl -X POST http://localhost:8080/export/exportByTemplate?exportTemplateId=2002 \
-H 'Content-Type: application/json' \
-d @- <<'JSON'
{
"filters": ["status", "=", "ACTIVE"],
"orders": ["createdTime", "DESC"],
"limit": 200
}
JSONFile template placeholder syntax:
{{ fieldName }}— replaced with the field value of each row{{ deptId.name }}— cascaded field reference (resolved by the ORM layer)- The
{{ }}syntax is normalized to underlying Fesod{}syntax before rendering
3. Dynamic Export
Export without a template by providing fields and filters directly.
Endpoint:
POST /export/dynamicExport?modelName={model}&fileName={fileName}&sheetName={sheetName}
Example:
curl -X POST 'http://localhost:8080/export/dynamicExport?modelName=Product&fileName=Products&sheetName=Sheet1' \
-H 'Content-Type: application/json' \
-d @- <<'JSON'
{
"fields": ["id", "name", "code", "status"],
"filters": ["status", "=", "ACTIVE"],
"orders": ["createdTime", "DESC"],
"limit": 200,
"groupBy": [],
"effectiveDate": "2026-03-03"
}
JSON4. Custom Export Handler
You can register a Spring bean implementing CustomExportHandler and reference it by name in
ExportTemplate.customHandler.
import io.softa.starter.file.excel.export.support.CustomExportHandler;
@Component("productExportHandler")
public class ProductExportHandler implements CustomExportHandler {
@Override
public void handleExportData(List<Map<String, Object>> rows) {
// custom post-processing
}
}Contract:
- You may update row values in place.
- You should not replace row map objects.
5. Export for re-import (by import template)
An import template is the one statement of what an importable sheet of its model looks like: its columns, the key each relation is named by (departmentId.code, jobLevelId.name), the unique key a row is matched back to its record by, its country and its dropdowns. A dynamic export knows none of that and writes relations by their display names, so its file does not go back in. Exported with the import template, the file is that template’s own workbook — the same headers, dropdowns, date formats and instruction sheet as the blank template from Download Template, built by ImportTemplateWorkbook — with the records under the header, and it imports back through the same template with no column mapping.
Endpoints (both on the export action; the service also asks for the import of the model, since such a file is for someone who can import it back):
POST /export/listImportTemplates?modelName={model}: the model’s own import templates a file can be exported with for the caller, in display order, each with the file’s columns (header,required), the headers a row is matched by (matchHeaders),ignoreEmptyandcountry. Empty for a caller who cannot both export and import the model.POST /export/exportByImportTemplate?modelName={model}&importTemplateId={id}: bodyExportParams(filters, orders, effective date;fieldsis ignored, the columns are the template’s). Returns the file;importTemplateIdon the export history records the template.
Offered only for a template a row can be matched back through:
importRuleisCreateOrUpdateorOnlyUpdate: exported withOnlyCreate, each record would be created again;- a model without effective-dated versions (
timeline): a file for re-import does not carry versions yet; - a non-empty
uniqueConstraintswith a column for each of its fields; a relation in the key is covered by a lookup column of it (companyIdbycompanyId.code); - no column that names several records (
roleIds.code): not written yet.
Each column is read so that the cell holds what that column’s import takes:
- a dotted column (
departmentId.code,employeeProfileId.passType.name) by its own path, the key it names the relation by; - a bare to-one column (
currency) by the related row’s id (currency.id): the import takes the id there, which for a code-as-id master is its code (SGD), not the name a display read gives; - every other column as an export reads it (
ConvertType.DISPLAY): an option by its label, a boolean as Yes / No — what the import takes, and what the template’s dropdowns list.
The caller’s view of the template:
- columns the caller may not write are already out of it (
ImportService.getImportTemplateDTO), as they are out of the blank template; - an optional column on a sensitive field the caller can never see (
PermissionService.getHiddenSensitiveFields) is left out of the file — the import reads a file without an optional column and then does not write that field; a required one makes the template unusable for them.
A template written for a country holds only that country’s rows, judged as the import judges a row’s country: by the company the row names (its first many-to-one onto the company model, legalEntityId on an employee; a company anchor joined at query time through its source path), and on the company model by its own country. A model naming no company is not filtered.
The workbook’s dropdowns and filter cover the records and 5000 rows more (OptionDropdownHandler, ImportSheetStyleHandler.forTemplate(fields, dataRows)), as a blank template’s cover 5000.
Transition: ExportHistory.importTemplateId is a new column. Under a scanner-scope that covers io\.softa\.starter\.file\.entity it is added at boot; an environment with an empty scanner-scope adds it by hand before the new jar starts (ALTER TABLE export_history ADD COLUMN import_template_id BIGINT NULL, plus its sys_field row the way that deployment adds catalog rows).