How to use id-based static data in repeats - using XPath expressions to show the appropriate labels instead of the id numbers or key values.
In a relational database environment, it's not uncommon to use surrogate keys - unique numbers that form the primary key on each table. These are arguably faster at a database level, because the database engine does not need to use multiple pieces of data when joining tables together.
However, surrogate keys pose a problem for a GUI designer. When managing data in forms, it's important to make the form easy to use. This generally means that we don't want to show the user the underlying keys or code values. Especially if the key value is an unintelligble number. Instead, we need to show relevant data fields that can be interpreted by the user.
For example our Client table has a foreign key to a list of Client Statuses. The foreign key column clnt-status-code-id references a table "code" with a surrogate key of code-id. Other columns on the code table contain the status description that should be displayed to the user:
However, surrogate keys pose a problem for a GUI designer. When managing data in forms, it's important to make the form easy to use. This generally means that we don't want to show the user the underlying keys or code values. Especially if the key value is an unintelligble number. Instead, we need to show relevant data fields that can be interpreted by the user.
For example our Client table has a foreign key to a list of Client Statuses. The foreign key column clnt-status-code-id references a table "code" with a surrogate key of code-id. Other columns on the code table contain the status description that should be displayed to the user:
======= ================
1 Active
2 Inactive
3 Dead
This means that our form should ideally show a drop-down (combo-box) that shows the descriptions. The client status field needs to store the equivalent id value.
Luckily, this turns out to be pretty simple to achieve once you employ some XPath. Assuming that the static data (containing the status code values) is stored in a instance separate from the client data, the XForms select1 looks something like:
<xf:select1 ref="clnt-status-code-id">
<xf:label>Status:</xf:label>
<xf:itemset nodeset="instance('static-data')/CSTA/code">
<xf:label ref="code-short-description">
<xf:value ref="code-id">
</xf:itemset>
</xf:select1>
In the end quite simple, and this means the form maintains separation of the UI from the data, without requiring javascript to move data around.
Luckily, this turns out to be pretty simple to achieve once you employ some XPath. Assuming that the static data (containing the status code values) is stored in a instance separate from the client data, the XForms select1 looks something like:
<xf:select1 ref="clnt-status-code-id">
<xf:label>Status:</xf:label>
<xf:itemset nodeset="instance('static-data')/CSTA/code">
<xf:label ref="code-short-description">
<xf:value ref="code-id">
</xf:itemset>
</xf:select1>
In the end quite simple, and this means the form maintains separation of the UI from the data, without requiring javascript to move data around.