Start page / Template development / Forms / Input components / FS_LIST: Migration Guide / FS_LIST, Type DATABASE → FS_INDEX

FS_LIST, DATABASE type → FS_INDEX

Contents

Please observe the following when converting the FS_LIST input component to FS_INDEX.

If data has been saved using FS_INDEX and it becomes necessary to revert to FS_LIST at a later date (due to a different data format), FS_LIST will no longer be able to read and interpret this data.

Actions and Rules

In FS_LIST components, the editing options (such as “New”, “Edit”, and “Delete”) that should be provided are defined via the <ACTIONS>/<ACTION> tag on the Form tab. In FS_INDEX components, they are defined via the Rules tab.

Here, it should be noted that the display logic of the available ACTIONS is reversed. If one of the ACTIONS has been defined for FS_LIST, nothing needs to be done for FS_INDEX. If an ACTION is missing in FS_LIST, this must be deliberately hidden for the FS_CATALOG input component.

The following ACTIONS for FS_LIST are automatically available in the FS_INDEX input component. However, they can be deliberately hidden:
ADD / NEW / REMOVE / EDIT

The following ACTIONS are automatically available and cannot be deactivated:
VIEW / UP / DOWN

The following ACTIONS are not supported by FS_INDEX:
DELETE / COPY / GOTO

Sample form

Form definition for the FS_LIST input component:

<FS_LIST name="IDENTIFIER" rows="5">
<DATASOURCE type="database" useLanguages="no">
<ACTIONS>
<ACTION name="ADD"/>
<ACTION name="REMOVE"/>
<ACTION name="UP"/>
<ACTION name="DOWN"/>
<ACTION name="GOTO"/>
<ACTION name="EDIT"/>
</ACTIONS>
<COLUMNS>
<COLUMN show="no">#identifier</COLUMN>
</COLUMNS>
<LAYOUT>
<ADD component="toolbar" constraint="top"/>
<ADD component="overview" constraint="center"/>
<ADD component="stackedview" constraint="bottom"/>
</LAYOUT>
<table>TABELLENVORLAGE</table>
</DATASOURCE>
<LANGINFOS>
<LANGINFO lang="*" label="Dataset selection"/>
</LANGINFOS>
</FS_LIST>

In this example, all buttons are allowed for FS_LIST except for “NEW”. This means that the “NEW” button must be hidden using a rule in the case of FS_INDEX.

Form definition for the FS_INDEX input component:

 <FS_INDEX name="IDENTIFIER">
<LANGINFOS>
<LANGINFO lang="*" label="Dataset selection"/>
</LANGINFOS>
<SOURCE name="DatasetDataAccessPlugin">
<TEMPLATE uid="schema.table"/>
</SOURCE>
</FS_INDEX>

Rule definition for the FS_INDEX input component:

<RULES>
<RULE when="ONLOCK">
<WITH>
<FALSE/>
</WITH>
<DO>
<PROPERTY name="NEW" source="IDENTIFIER"/>
</DO>
</RULE>
</RULES>

Labels

The labeling of inputs in an FS_LIST input component is modeled using #item.IDENTIFIER inside the LABELS/LABEL tag. Inputs in an FS_INDEX input component are not labeled inside the form definition; instead, they are labeled via a corresponding snippet definition. The snippet definition of the selected table templates is used for this purpose.

Height of the input component

In FS_LIST components, the height parameter relates to the height in pixels; in FS_INDEX, it relates to the number of rows.

Number of entries

In FS_LIST components, the maxEntries parameter is used to determine how many entries are allowed to be added. In FS_INDEX, this is done via a rule with the SIZE property.

FS_LIST

<FS_LIST name="IDENTIFIER" rows="5">
<DATASOURCE type="database" useLanguages="no" maxEntries="4">
<ACTIONS>
<ACTION name="ADD"/>
<ACTION name="REMOVE"/>
<ACTION name="UP"/>
<ACTION name="DOWN"/>
<ACTION name="GOTO"/>
<ACTION name="EDIT"/>
</ACTIONS>
<COLUMNS>
<COLUMN show="no">#identifier</COLUMN>
</COLUMNS>
<LAYOUT>
<ADD component="toolbar" constraint="top"/>
<ADD component="overview" constraint="center"/>
<ADD component="stackedview" constraint="bottom"/>
</LAYOUT>
<table>TABLETEMPLATE</table>
</DATASOURCE>
<LANGINFOS>
<LANGINFO lang="*" label="Dataset selection"/>
</LANGINFOS>
</FS_LIST>

FS_INDEX

<RULE>
<WITH>
<LESS_THAN>
<PROPERTY name="SIZE" source="IDENTIFIER"/>
<NUMBER>4</NUMBER>
</LESS_THAN>
</WITH>
<DO>
<PROPERTY name="ADD" source="IDENTIFIER"/>
</DO>
</RULE>

Output

If entries are output using $CMS_FOR(...)$, the .getValues (or .values in Bean syntax) method call must be added in the case of FS_INDEX:

FS_INDEX

$CMS_FOR(VARIABLE, LISTNAME.values)$
$CMS_VALUE(VARIABLE.ELEMENT)$
$CMS_END_FOR$

FS_LIST

$CMS_FOR(VARIABLE, LISTNAME)$
$CMS_VALUE(VARIABLE.ELEMENT)$
$CMS_END_FOR$

When using DatasetDataAccessPlugin, you must now use var.<Name of the inner input component> instead of var.formData.<Name of the inner input component> when accessing the dataset's input components:

FS_INDEX

$CMS_FOR(VARIABLE, LISTNAME.values)$
$CMS_VALUE(VARIABLE.formData.ELEMENT)$
$CMS_END_FOR$

FS_LIST

$CMS_FOR(VARIABLE, LISTNAME)$
$CMS_VALUE(VARIABLE.ELEMENT)$
$CMS_END_FOR$
Important Rendering of an FS_INDEX input component using $CMS_VALUE(...)$ is no longer supported and will cause generation warnings (“use of deprecated value generation method for an index editor”). Please always use $CMS_FOR(...)$ for the rendering (see FS_INDEX output example).

Query in the script

If entries are being read out in a script, the script must be extended in the following way:

FS_INDEX

FormData myFormData = this.mySection.getFormData();
if (st_myDatasetListIndex != null) {
Index myFormfield = (Index) myFormData.get(null, "st_myDatasetList").get();
final DataAccessSession st_myDatasetListDataAccessSession = myFormField.createSession(context);
for (Index.Record record : myFormfield) {
Dataset dataset = (Dataset) st_myDatasetListDataAccessSession.getData(record.getIdentifier());
FormData formData = dataset.getFormData();
Integer myNumber = (Integer) formData.get(null, "st_number").get();
...
}

FS_LIST

FormDataList myListFormDataList = (FormDataList) this.mySection.getFormData().get(null, "st_myDatasetList").get();
for (IdProvidingFormData formdata : myListFormDataList) {
Integer myNumber = (Integer) formdata.get(null, "").get();
...
}

Simplified queries are possible with FirstSpirit 2019-11. Before version 2019-11, <FormField>.createSession(<broker>) was not yet possible. <GomIndexSource>.createSession(<broker>, boolean) was used instead.

Automatic sorting via "sortOrder"

The FS_LIST functionality of sorting entries automatically for the display based on the available data is not available for FS_INDEX. However, it is possible to sort entries manually in FS_INDEX.

The following example shows how the snippets of the FS_INDEX input components can be automatically sorted before being output:

<Input component>.values.sort(x->x.formData.<Sorting field>).map(x->x.formData.<Output field>).toString(",")

In the example script below, you can see how an FS_INDEX input component can be sorted accordingly using FS_BUTTON:

 <FS_BUTTON name="st_sortDatasets"
onClick="script:custom_index_sort"
style="button"
useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Sorting"/>
</LANGINFOS>
<PARAMS>
<PARAM name="field">#field.st_datasets</PARAM>
<PARAM name="criteria">Name</PARAM>
</PARAMS>
</FS_BUTTON>

<FS_INDEX name="st_datasets">
<LANGINFOS>
<LANGINFO lang="*" label=""/>
</LANGINFOS>
<SOURCE name="DatasetDataAccessPlugin">
<TEMPLATE uid="MySchema.MyDataset"/>
</SOURCE>
</FS_INDEX>

Source code of the relevant script

formData = element.getFormData();
form = formData.getForm();
gomIndex = form.findEditor(field.getName());
gomIndexSource = gomIndex.source();
dataAccessSession = gomIndexSource.createSession(context, false);

index = field.get();

datasets = new ArrayList();
for (record : index.iterator()) {
identifier = record.getIdentifier();
dataset = dataAccessSession.getData(identifier);
datasets.add(dataset);
}

datasets.sort(new Comparator() {
compare(dataset1, dataset2) {
value1 = dataset1.getEntity().getValue(criteria);
value2 = dataset2.getEntity().getValue(criteria);
return value1.compareTo( value2 );
}
});

index.clear();

for (dataset : datasets.iterator()) {
identifier = dataAccessSession.getIdentifier(dataset);
record = index.create(identifier);
index.add(record);
}

field.set(index);

The script can be rewritten in such a way that iteration is performed via all the relevant nodes and these nodes are sorted as required.

Manual sorting via "PERSISTENCEINDEX"

This functionality, which now specifically saves the sequence for each FS_INDEX input component, is provided in the FS_INDEX input component as standard. Datasets can therefore be sorted easily and referenced at various points. To sort each FS_LIST input component for the FS_INDEX input component, it is necessary to set the sequence of the datasets once per script.
In the case of the FS_LIST component, the sequence is saved via a corresponding column for each linked dataset. In the case of the FS_INDEX input component, this is now initiated via the fs_meta_data column on the FS_INDEX page.

Migration can be performed using the following example script:

dataset = context.getElement();
dataset.setLock(true, false);
formData = dataset.getFormData();
form = formData.getForm();
indexComponent = form.findEditor("images");
source = indexComponent.source();
session = source.createSession(context, false);
positions = Collections.synchronizedSortedMap(new TreeMap());
pictures = formData.get(null, "images");
index = pictures.get();

for (record : index.iterator()) {
data = session.getData(record.getIdentifier());
formData = data.getFormData();
position = formData.get(null, "position").get();
positions.put(position, record);
}

sorted = positions.entrySet().stream().sorted(Map.Entry.comparingByKey());
index.clear();

for (el : sorted.iterator()) {
index.add(el.getValue());
}

pictures.set(index);
dataset.setFormData(formData);
dataset.save("Re-sort", false);
dataset.setLock(false, false);

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.4 | Data privacy