Edit pages are used to modify the attributes of a single row. Their
definition and their operation is very similar to the insert pages. In
practice, it is not possible to have a stand-alone edit page; rather they should
be accessed by following a link from another page. In other words, all edit pages
receive parameters. The parameter is essential to the operation of the
page, as it enables the page to retrieve the row that should be
edited from the database. Currently the edit pages can edit a single row
at a time. Nonetheless, it
is possible to extend the tool to support other kinds of edit pages in the future.
Although the
syntax used for describing edit pages is very similar to the insert pages, there are some differences that should be noted:
In spite of the fact that edit pages are single-row, it is required to include the <primarykey> tag in
addition to the <targettable> tag in their definition. For the insert pages we only needed the <primarykey>
tag in the hybrid type because the tool needs to know how to link the rows
together by using the foreign key and primary key attributes. However in the
edit pages, the primary key is always required when the tool is updating the
table. As the first example, the following figure shows the contactedit page,
which is used to modify the personal information for a specific
contact.
<?xml version="1.0" encoding="UTF-8"?>
<page type="edit">
<title>Edit Contact</title>
<icon>contactedit.gif</icon>
<top>
<targettable>contact</targettable>
<primarykey>id</primarykey>
<fields>
<field name="name" caption="First Name"
size="20"/>
<field name="lastname" caption="Last Name"
size="30"/>
<field name="phone" caption="Phone#" size="15"/>
<field type="text" name="address"
caption="Address" size="50" optional="true"/>
</fields>
<exportcombo>
<field>lastname</field>
<field>name</field>
</exportcombo>
</top>
</page>
This page is accessed by following the "Edit" link for some row
in the contactlist page. The link sends the id of the intended contact to
this page. In the edit pages, this values is used to determine
the row that should be edited. However there is no <pageparam> tag in edit
pages. It is because in every edit page there are two implicit <querysource>
and <pageparam> tags that are automatically defined by the tool. The <pageparam>
tag contains the same attribute as the one specified in the <primarykey> tag
and the <querysource>
tag defines a simple query which returns every row in the <targettable>. Retrieving the
intended row is accomplished by using the two
implicit <querysource> and <pageparam> tags. For example in this page the tool assumes the following values for the two tags:
<querysource>SELECT * FROM contact</querysource>
<pageparam>id</pageparam>
Similar to the insert pages, in edit page the data entry fields are defined by
the <field> tags. In this page there are four <field> tags corresponding to
the four attributes of the contact table. There is no difference between definition of <field> tags in edit pages and insert pages. The
following figure shows the contactedit page in a browser.
Contact edit
page in a browser
When the user submits this
form, an UPDATE query is constructed and submitted to the database to update the
new values for the attributes of the row. The edit pages also support the "display" fields. If an edit page has been designed to modify only some of
the attributes in a table, it is good practice to show the other attributes as
display fields on the form.
The navigation structure of the address book application denotes that
we need another edit page for editing the email addresses. This page is
accessed by following the "Edit" links next to the email addresses displayed in
the body of contactdetail page. The definition and output of this page are
shown in the following figures.
<?xml version="1.0" encoding="UTF-8"?>
<page type="edit">
<title>Edit Email Address</title>
<icon>emailedit.gif</icon>
<top>
<targettable>email</targettable>
<primarykey>id</primarykey>
<fields>
<field name="email" caption="Email Address"
size="50"/>
<field type="text" name="comment"
caption="Comment" size="50" optional="true"/>
</fields>
</top>
</page>
Email edit
page in browser |