Dynamic Data Analysis on the Web-a Design Approach - Presenting data
(Page 6 of 13 )
To present and explore the result data, the page author will require some further custom JSP tags. These custom tags will often be general purpose, and leave the page author in control of the layout and display attributes of the result values. In certain cases, specialised custom tags might provide a more sophisticated presentation of the entire result set.
Listing 2 shows some general purpose custom tags which can be used to iterate through the result values and extract individual values for presentation. In this case, the result values from the data definition shown in Listing 1 are formatted as a series of HTML tables, one for each year of sales results.
Listing 2. General purpose data presentation tags
<%@ taglib uri="/WEB-INF/tlds/dp.tld" prefix="dp" %>
<dp:forSlices id="slices" dataRef="sales">
<TABLE border>
<TBODY>
<TR>
<TH>Year</TH><TH>Product</TH><TH>Unit Sales</TH><TH>Revenue</TH>
</TR>
<dp:forRows id="rows" sliceRef="slices">
<TR>
<TD>
<dp:write>
<dp:valueFromColumn rowRef="rows">
<dd:dimension>Year</dd:dimension>
</dp:valueFromColumn>
</dp:write>
</TD>
<TD>
<dp:write>
<dp:valueFromColumn rowRef="rows">
<dd:dimension>Product</dd:dimension>
</dp:valueFromColumn>
</dp:write>
</TD>
<TD align="right">
<dp:write>
<dp:valueFromColumn rowRef="rows">
<dd:measure>Unit Sales</dd:measure>
</dp:valueFromColumn>
</dp:write>
</TD>
<TD align="right">
<dp:write>
<dp:numberFormat style="currency" locale="server">
<dp:valueFromColumn rowRef="rows">
<dd:measure>Revenue</dd:measure>
</dp:valueFromColumn>
</dp:numberFormat>
</dp:write>
</TD>
</TR>
</dp:forRows>
</TBODY>
</TABLE>
</dp:forSlices>
Slice and row iteration tags
In Listing 2, the taglib directive establishes the scope of the data presentation tags within the JSP with a prefix of dp.
The forSlices tag references a data tag by using the dataRef attribute to specify the id of the data tag. In this case, it references the data tag defined in Listing 1. The forSlices tag will evaluate its body for every slice in the result data. It, in turn, has an id attribute by which it might be referenced. In the example, an HTML table with borders switched on is defined for each slice. The page author, knowing the dimensions and measures to be presented, has included a row of suitable headers in each table. This is followed by a table row for each row of data within the slice.
The forRows tag references a forSlices tag using the sliceRef attribute. The forRows tag will evaluate its body for each row in the result data slice from the referenced forSlices tag. It, in turn, has an id attribute by which it might be referenced.
Next: Value formatting tags >>
More Web Services Articles
More By developerWorks