Web DbForms
Pages: 1, 2, 3, 4, 5
Application Hookups
Introduction
Along with a lot of built-in functionality, DbForms offers many optional features, which may be configured and utilized via the XML configuration file, attributes of custom tags, etc.
But it would be neither possible nor useful to create a system which has a built-in hardcoded answer for every problem or requirement which could appear during the development process (and life cycle) of a database application. Because it is impossible to foresee all eventual use cases and user's needs, such a monolithic approach would certainly restrict the application developer sooner or later.
Interface DbEventInterceptor
Every system which wants to get around this problem offers a kind of "programming facility" or "Application Programming Interface." So does DbForms.
DbForms provides an interface, DbEventInterceptor, which intercepts database operations DbForms is about to perform or has finished. This interface provides the following methods.
Listing 11. Methods definied in interface DbEventInterceptor
public int preInsert(HttpServletRequest request, Hashtable fieldValues, DbFormsConfig config, Connection con)
throws ValidationException;
public void postInsert(HttpServletRequest request, DbFormsConfig config, Connection con);
public int preUpdate(HttpServletRequest request, Hashtable fieldValues, DbFormsConfig config, Connection con)
throws ValidationException;
public void postUpdate(HttpServletRequest request, DbFormsConfig config, Connection con);
public int preDelete(HttpServletRequest request, Hashtable fieldValues,DbFormsConfig config, Connection con)
throws ValidationException;
public void postDelete(HttpServletRequest request, DbFormsConfig config, Connection con);
public int preSelect(HttpServletRequest request, DbFormsConfig config, Connection con)
throws ValidationException;
public void postSelect(HttpServletRequest request, DbFormsConfig config, Connection con);
As the names indicate, the preXxx() methods get called before the respective database operation is performed, the postXxx() methods get called after the operation has finished.
PreXxx() methods return a value indicating if the operation should be performed or not:
DbEventInterceptor.GRANT_OPERATIONDbEventInterceptor.DENY_OPERATION
PostXxx() methods do not return a value, as the operation is already done.
Installing the Hookups
How do we tell DbForms when to invoke which interface implementation?
This information must be provided by the DbForms XML configuration file. Similar to the granted-privileges security constraint (as described above), the XML element defining an Interceptor has to be placed inside of a table element.
<table name="customer">
<field name="id" fieldType="int" isKey="true"/>
<field name="firstname" fieldType="char" />
<field name="lastname" fieldType="char" />
<field name="address" fieldType="char" />
<field name="pcode" fieldType="char" />
<field name="city" fieldType="char" />
<interceptor
className = "com.foo.bar.CustomerValidatonChecker"
/>
<interceptor
className = "com.foo.bar.TransactionLogger"
/>
</table>
The semantics of these declarations could be described as "Invoke com.foo.bar.CustomerValidatonChecker and com.foo.bar.TransactionLogger, if the user is about to read, insert, update or delete data from table customer and call the appropriate methods of those objects"
Rapidly Generating Standard Views using XSL
As demonstrated previously, DbForms can help speed up development of Web-based database applications. But there are still many monotonous tasks to do -- you still have to write the JSP code for each view. The more views you have to write, the more monotonous work you have to do.
Because in many cases the JSPs are very similar to each other, you'll probably do much of the work using copy-and-paste and then apply the necessary changes by hand. This works well, but do we really want this kind of development? I don't think so!
For instance, say you have a database containing 40 tables and you want to write a Web-based data maintenance tool against it. Imagine you want for each table a "list view" (allowing the user to view all elements of the table at one time) and a "single view" (viewing only one row at a time), so that the user may view and edit the data in two different ways. Well, having 40 tables and two views for each indicates that you will have to create (40x2 =) 80 JSP files, and an application menu as well. This means that at least 81 JSP files need to be written!
Thanks to XML and XSL, DbForms provides a pretty simple and straightforward solution:
- For every "standard layout" (in our application we have "listview layout," "singleview layout," and "menu layout") we create one XSL file. Each XSL file gets applied to your application's XML configuration file (this file contains detailed information about all tables and fields of the database).
- The result of the XSL transformations are JSP files, created according to the style rules defined in the XSL file.
|
The very good news is that the whole process shown in Figure 8 is encapsulated by a SWING-based tool called DevGui, shown in Figure 9. You can use this application to generate the XML-formatted database metadata, to apply XSL stylesheets to it, and to deploy and test the resulting JSP files.
View Figure 9. DevGui: a tool for automatically generating JSP views.
DbForms Custom Tag Library
| Tag Name | Description |
dbform |
A database application form (root element of a JSP view) |
header |
Renders a header tag. It should be nested within a DbForm tag |
body |
Renders a body tag. It should to be nested within a DbForm tag |
footer |
The footer grouping tag. It is supposed to be nested within a DbForm tag |
label |
Renders a database-data-driven label, which is a passive element (it can't be changed by the user). It is reserved for use with read-only data (i.e., primary keys you don't want the user to change, etc.) |
dateLabel |
Similar to label, but with special attributes for formatting date values |
dataLabel |
Label; a tag for data presentation. Not for editing data (can never be used as an input field) |
textField |
Renders a database-data-driven textfield, which is an active element -- the user can change data |
dateField |
Renders a database-data-driven date field, which is an active element -- the user can change data. Very similar to textField, but it has special attributes for formatting date values |
textArea |
Renders a HTML textarea element |
tableData |
External data to be nested into radio, checkbox, or select tag. (Only useful in conjunction with radio, checkbox, or select tag) |
queryData |
External data to be nested into radio, checkbox, or select tag. (Only useful in conjunction with radio, checkbox, or select tag) |
staticData |
External data to be nested into radio, checkbox, or select tag. (Only useful in conjunction with radio, checkbox, or select tag) |
staticDataItem |
Data to be nested into staticData element |
file |
Renders an upload button for uploading files into BLOBs or DISKBLOBs |
radio |
Renders a HTML radio element or a whole group of them |
checkbox |
Renders a HTML checkbox element or a whole group of them |
select |
Renders a HTML select element, including embedded option elements. |
linkURL |
Generates a link to a DbForms view |
position |
Element to be embedded inside a linkURL element |
insertButton |
Renders an insert button |
deleteButton |
Renders a delete button |
updateButton |
Renders an update-button |
navPrevButton |
Renders a navigation button for scrolling to previous row(s) of the current table |
navNextButton |
Renders a navigation button for scrolling to next row(s) of the current table |
navFirstButton |
Renders a navigation button for scrolling to the first row(s) of the current table |
navLastButton |
Renders a navigation button for scrolling to the last row(s) of the current table |
navNewButton |
Renders a navigation button for creating a new row of data |
gotoButton |
Renders a button for jumping to a JSP view |
base |
Renders a HTML base tag |
errors |
Custom tag that renders error messages |
associatedRadio |
Enables the end user to define a row by selecting the radio button rendered by this tag |
blobURL |
Generates a URL pointing to a servlet for downloading a binary object |
sort |
Renders a select box for switching the order state of a field (ascending, descending, none) |
style |
Generic style tag |
Joachim Peer is a Sun certified programmer and independent J2EE developer. He holds a masters degree in Management Information Systems.
Return to ONJava.com.
