A button that exports the contents of a specified table to a CSV file. You must contain the Export Table Button in a command Form.
To provide custom content for the export, such as to provide a set of columns with more machine-friendly formatted data, you can bind this control's exportProvider
property value to a separate com.webmethods.caf.faces.data.ITableContentProvider
instance. An ITableContentProvider
designed for CSV export is the com.webmethods.caf.faces.data.export.CSVExportProvider
class. It maps the content of an existing ITableContentProvider
, that is the provider that delivers the raw data for the table to a custom set of columns with each column's content specified by a binding expression.
The following example demonstrates creating a CSVExportProvider
in a custom page bean method. You bind the property to the getter method, myExportProvider
, to the control's exportProvider
property value. There is an existing table content provider for the raw table data, accessible using the getMyExistingTableContentProvider()
method. The application creates four columns: ID, Title, Priority, and Priority Name and specifies the content of these columns with binding expressions: #{row.projectId}_#{row.id}"
, #{row.title}
, #{row.priorityValue}
, and #{row.priorityName}
. Specify the name of the row variable as the third argument to the CSVExportProvider
constructor. For each row, the content of the ID column in the exported table generates from the value of the existing table row's projectId
and id
properties. The content of the Title column generates from the value of the existing table row's title
property.
public ITableContentProvider getMyExportProvider() {
ITableContentProvider existingProvider =
getMyExistingTableContentProvider();
Map keys = new LinkedHashMap();
keys.put("ID", createValueBinding("#{row.projectId}_#{row.id}"));
keys.put("Title", createValueBinding("#{row.title}"));
keys.put("Priority", createValueBinding("#{row.priorityValue}"));
keys.put("Priority Name", createValueBinding("#{row.priorityName}"));
return new CSVExportProvider(existingProvider, keys, "row");
}
In the code example above, the exported table's column labels are the column keys, such as ID, Title, Priority, and Priority Name. As a best practice use the String resources from a resource bundle instead of hard-coding the labels. The labels in this example are hardcoded. The examples uses A LinkedHashMap to ensure that the columns are exported in the order they were added to the keys map. The exported CSV might look like the following:
ID, Title, Priority, Priority Name
higgins_123, Nothing Works, 1, Critical
higgins_ABC, "Name is "MWS"", 3, Medium
The export processing handles the escaping of column values such as in the example output above, the Name is "MWS" value is escaped as "Name is ""MWS""".
Info | Value |
---|---|
Component Type | com.webmethods.caf.faces.export.ExportTableButton |
Handler Class | com.webmethods.caf.faces.component.DynamicControlHandler |
Renderer Type | None |
Description | Exports the table data to a CSV file |
Palette Location | CAF Html/Control/Table/Export Table Button |
Client-Side Model | CAF.Link.Model |
Name | Required | Type | Description |
---|---|---|---|
exportCharacterEncoding | false | javax.el.ValueExpression
(must evaluate to java.lang.String )
|
Character Encoding for the exported data file
If not specified, the default value is "UTF-16LE". |
exportExcludeComponentsCSV | false | javax.el.ValueExpression
(must evaluate to java.lang.String )
| CSV of Component IDs that should be excluded when exporting the table data |
exportFileName | false | javax.el.ValueExpression
(must evaluate to java.lang.String )
|
The filename for the exported table data
If not specified, the default value is "export.csv". |
exportProvider | false | javax.el.ValueExpression
(must evaluate to com.webmethods.caf.faces.data.ITableContentProvider )
| Provider for exported content |
exportShowEncodingDialog | false | javax.el.ValueExpression
(must evaluate to boolean )
|
True to show the character encoding selection dialog before exporting
If not specified, the default value is "true". |
for | false | javax.el.ValueExpression
(must evaluate to java.lang.String )
| Table Control to which this button applies |
id | false | java.lang.String | Control identifier |
rendered | false | javax.el.ValueExpression
(must evaluate to boolean )
|
True to render control; false to ignore it
If not specified, the default value is "true". |
Output generated by Vdldoc View Declaration Language Documentation Generator.