Standalone Table Configuration
Creating Table Editors
We can edit the standalone lookup table public.staff in our Weave client XML using the following two steps:
Create a server-side edit config for the table:
<editor:table id="e.staff">
<label>Staff</label>
<datasource>ds.postgresql</datasource>
<table>public.staff</table>
<key>id</key>
</editor:table>
The table the editor will be updating is thepublic.staff
table in the ds.postgresql
database. The table must have a column called id
that contains the unique keys for the rows in the table.
You don't need to specify the key column if the table contains a single primary key column, Weave will determine that and use that column to identify rows.
Once saved, a table editor should appear in the Config application of the Weave Admin tool. See end of this document.
Create a Weave client component to enable the user to conduct the editing.
The declared<type>
oftable
means the view component discovers all editors of type table (iee.staff
above).
<view id="editor.panel.simplegrid">
<label>Lookups</label>
<location>west</location>
<type>table</type>
</view>
If more than one editor exists, the <view>
component will discover them and present the user with a pulldown menu to select the editor they want to work with. Creating another table editor for the public.visit_purpose
lookup table we get:
<editor:table id="e.visit_purpose">
<label>Visit Purpose</label>
<datasource>ds.postgresql</datasource>
<table>public.visit_purpose</table>
<key>id</key>
</editor:table>
The <view>
component will now show a pulldown menu that include the Staff
and Visit Purpose
editors as follows.
The user can select the e.staff
table editor from the list using the name Staff
.
Controlling Column Display
By default, the above editor will display all columns for the user and allow them to edit all columns (except the key column).
To demonstrate that the default editor will display all columns in the underlying table let’s add another column, age
, to the staff
table:
Refreshing the client, we can see the new age column appears through our default editor:
Nowe you can specify which columns you want to expose by adding <parameter>
tags to the editor config (in a similar manner to the spatial editing configuration, and the attribute search configuration), this also allows you to explicitly specify how you want Weave to expose the column to the user, for example, if you need to set a list of values that the user can enter for a particular column since Weave will just create a basic representation of the columns if they're not explicitly specified.
Note: instead of creating an edit config xml for the staff
table by hand, you can create a default configuration for the staff table from the osgi
console using the editor
command, e.g.
Which will produce (change id
from staff
to e.staff
):
This editor config overrides the default editor and will only ever show the name
column.
Now if we use the osgi
editor command to rebuild the definition to include the age
column we get:
Before we use this, let’s implement a check constraint on the age
column so that its minvalue
must be greater than or equal to 0 and its maxvalue
less than or equal to 100. We do this by modifying its parameter as follows (note also the change of id
of editor:table
to e.staff_age
):
Execute the following steps:
Refresh the client.
Select the
Staff and Age
editor from the pulldown.Double click on the row containing Wilma Flintsone.
In the new form, change her age to 101
Notice “The maximum value for this field is 100” alert is immediately displayed against the row.Change her age to 39 and press Submit.
Notice the update successful notice in the bottom right of the client.
Checking Table Editor Creation
If when an editor:table is successfully created, it should appear in the Config application of the Weave Admin tool as shown.