8.3.  Element table

The table element is perhaps the most complex element. It contains the majority of the information needed by DbForms to render the DbForms JSP tags. A table element is needed for for each table to be used with DbForms.

A starting set of table elements as well as a basic dbconnection element can be generated using the DevGui tool. This tool, which is described in Chapter 5, DevGui , verifies database connectivity and then uses JDBC capabilities to query the metadata for tables in the database. This can be a signficant time-saving step.

The nesting and ordering of subelements within each table tag is shown below.

   <table>
     <field/>
     <calc/>
     <foreign-key/>
     <events>
       <event/>
     </events>
     <interceptor>
       <param/>
     </interceptor>
     <granted-privileges/>
   </table>

The top level subelements, field through granted-privileges may each occur zero or more times except events which is optional but may appear a maximum of one time.

There is no element content in the any of the elements. All information is supplied in the attributes of these elements and the attributes of their subelements.

The table element itself has one required attribute, name, giving the name of the table and a number of optional attributes. All of the attributes are listed below.

name
The name of the table. Required.
orderBy
The name of a column by which the table should be sorted. The order defined in this element is not changeable by the user and appears in the application to be the natural order of rows in the table. If omitted or set to false, the order is determined by the database system. Optional.
dataAccessClass
This is the fully-qualified name of a Java class that implements the data access functionality for the table, replacing JDBC. Currently, this is used for XML as discussed in Chapter 25, Using XML for Data input but developers may define other data access classes. All data access classses must extend the DbForms class org.dbforms.event.datalist.dao.DataSource. Optional.
escaperClass
This is the fully-qualified name of a Java class that implements functionality to place escape characters in column data so the HTML display is as desired and to place escape characters in a field value before it is stored in the database. The Java class must implement DbForms interface org.dforms.util.IEscaper. Optional.
alias
This attribute is used for XML data sources. It provides a URL to access data for an XML "table". The URL includes a query portion (following the '?' in the URL) that is used as an XPath expression to obtain the data. See Chapter 25, Using XML for Data input for more details. Optional.
blobHandling
If this attribute is set to "classic", DbForms will use its original method of handling BLOBs which involved storing BLOB data in individual disk files. When this attribute is omitted or has any other value, the database management system is used to store BLOBs in appropriate table columns. When classic BLOB handling is used, the directory and encoding attributes of field subelements may be used to control where and how BLOB files are handled. Optional.
defaultVisibleFieldsFormat
This attribute sets the default for the foreign-key attribute format as a convenience when fields from the table are referenced as foreign keys. See Chapter 19, Foreign Key support within DbForms for more information. Optional.
defaultVisibleFields
This attribute sets the default for the foreign-key attribute visibleFields as a convenience when fields from the table are referenced as foreign keys. See Chapter 19, Foreign Key support within DbForms for more information. Optional.

The field element describes a column in the table. There are two required attributes, name, giving the name of the column in the table, and fieldType, giving the data type of the column. There are also many optional attributes. All of the attributes are listed below.

name
This is the name of the field (column) as known in the database. Required.
fieldType
This is the type of the field. The list of valid values is shown below. Required. The comparison within DbForms uses the Java method String.startsWith() so, for example, Oracle's varchar2 matches the varchar type listed below. Use of an unsupported column type will result in a Java exception while reading the dbforms-config.xml file which will generally render the application unusable.
Character Types
DbForms field types char, varchar, longchar, long varchar, and text.
Integer Types
DbForms field types int, smallint, long, and tinyint.
Numeric Types
DbForms field types numeric, number, and decimal.
Date and Time Types
DbForms date, timestamp, and time.
Floating Point Types
DbForms field types double, float, and real.
Large Object Types
DbForms image, blob, and diskblob.
Boolean Types
DbForms field type bool.
size
This attribute gives the size of the field in the database. Optional.
isKey
This attribute should be set to true if the field is a key field. If omitted, the field is not a key. Optional.
sortable
This attribute should be set to true if the field will be made available for sorting. If omitted, the field is not sortable unless it is a key field. Optional.
autoInc
This attribute should be set to true if the field will be populated automatically by the database. Optional.
directory
This attribute is used with classic BLOB handling where DbForms stores BLOB data in individual files. The value of this attribute indicates the directory where the BLOB file will be stored. This directory must exist and be must be writeable by the servlet engine. Optional.
expression
This attribute is used for XML data access. The value is taken to be a relative XPath expression that is attached to the URL given by the alias attribute in the enclosing table element. Optional.
defaultValue
This value is used to supply a default for the given field when a row is inserted into the database. Optional.
alias
Not currently used.
escaperClass
This is the fully-qualified name of a Java class that implements functionality to place escape characters in column data so the HTML display is as desired and to place escape characters in a field value before it is stored in the database. The Java class must implement DbForms interface org.dforms.util.IEscaper. Optional.
encoding
This attribute is used with classic BLOB handling where DbForms stores BLOB data in individual files in the directory given by the directory attribute. When encoding is set to true, file names for BLOB objects are generated by DbForms so there is no possibility of one BLOB object overwriting another. If encoding is false or is omitted, the remote file name of an uploaded BLOB file is used by DbForms. This means that files of the same name will overwrite each other. Optional.

The calc element is similar to the field element except that the encoding attribute is not allowed. A field defined within a calc element is not populated by the user. Rather, the value is generated by an interceptor.

Columns in a table that are foreign keys in the SQL sense should be described in using the element foreign-key rather than the field element. This allows DbForms to handle the field differently. There are limitations, however, on DbForms foreign key handling. See Chapter 19, Foreign Key support within DbForms for more details.

Every table uses, by default, the standard event configuration established in the events subelement nested directly within the root dbforms-config element. A developer can choose, however, to override the event class associated with a certain type of event, by adding and configuring the events element within a table element.

The events element itself is merely a container for one or more event subelements within it. Element events has no attributes. Each event element may have a number of attributes and may enclose nested param subelements. See Chapter 22, Pluggable events and especially Section 22.5, “Override the event classes on a table-by-table basis ” for more details.

The interceptor element is used for declaring interceptor classes locally for a particular table. See the discussion later in this chapter on the interceptor element for details of the attributes and the param subelement. As mentioned in Chapter 15, Application hook-ups (Interceptors) , it is also possible to declare interceptors globally to apply to all tables. Globally declared iterceptors are invoked for all tables but interceptors declared for specific tables are invoked only for that table. If both table-specific and global interceptors are defined, the table-specific iterceptor is invoked first and, if it signals success, the global interceptor is then invoked.

By default, all users of the DbForms application have full access to read and write all of the tables defined in dbforms-config.xml.The granted-privileges element has four optional attributes that can establish limits for specific user roles. The attributes are select, insert, update, and delete. User roles are those defined in the application web.xml file. See Chapter 9, Security for more details.