Formatting Data

When you use a Data Provider to retrieve some data and do not specify a formatting template, the returned data is displayed with the minimum of formatting.

Example: Displaying a list of Employees from a Database

The following request returns an unformatted set of data:

<connect MOD="TEMPLATE" SRV="SQL"
 DB="jdbc:odbc:accesssample"
 SQL="Select * from employee">
</connect>

To format the returned data build a formatting template. These should not be confused with Presentation Templates or Authoring Templates used in the Web Content Management Authoring Portlet (Web Content Authoring).

 

Formatting Templates

The Web Content Management application can format retrieved data before it is returned to the browser. This formatting is completely customizable, and is achieved by using a HTML file as a formatting template for the returned data. The formatting template specifies the HTML code to use to replace the "Connect" tag, including the HTML code to use for each record (row) found in the retrieved data. A formatting template is specified by using the "Template=" parameter.

Example:

In this example, TEMPLATE="sqldb2.html" has been added. This formatting template is used to apply formatting to the retrieved data.

<connect MOD="TEMPLATE" SRV="SQL"
 DB="jdbc:odbc:accesssample"
 SQL="Select * from employee"
 <b>TEMPLATE="sqldb2.html"</b> >
</connect>

 

Formatting Template Structure

Formatting templates are written in HTML. As such, they can take advantage of all the standard HTML functionality. To this are added Web Content Management specific tags that are used to build Result Sets. (Result Sets are covered in the next chapter.) The best and simplest way to control the layout of a formatting template (and Result Sets) is to use HTML tables.

Example:

The following code is an example of how tables are used to format the layout of a formatting template and Result Sets:

<html>
<head>
<title>SQL Template File</title>
<link href="style.css" type="text/css" rel="stylesheet"></link>
</head>
<body>
<TABLE cellspacing="2" cellpadding="2" valign="top"> align="left" border="1">
<TR><TH valign="top"> align="left" class="blue"><u>Employee Number</u></TH>
<TH valign="top"> align="left" class="blue"><u>Full Name</u></TH></tr>
<RESULTSET>
<LOOP>
<tr>
<TD valign="top"> align="left"><FIELD NAME="employeenumber">
<TD valign="top"> align="left"><FIELD NAME="firstnme"><FIELD NAME="lastname"></td>
</tr>
</LOOP>
</RESULTSET>
</TABLE>
</body>
</html>

 

Referencing Formatting Templates

Formatting templates can be saved as File Resource Components. These can then be referenced within "Connect" tags.

Example:

In this example, data from a Database is processed using a formatting template called "sqldb2.html". This has been saved as a File Resource Component called "sqldb2". The following code is then placed in a formatting template. The File Resource Component is used as the formatting template. When the page is rendered in a Web Content Management environment, the "Connect" tag is processed and the data is formatted by the formatting template.

<connect MOD="TEMPLATE" SRV="SQL" 
     DB="jdbc:odbc:accesssample" 
     SQL="Select * from employee"
     USER="UserName" 
     PWD="password" 
     TEMPLATE="<AptrixLibCmpnt name="sqldb2" />"
</connect>

Parent topic: Displaying Data from Databases.


IBM Workplace Web Content Management - V5.1.0.1 -

 

Workplace Web Content Management is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.