Previous Chapter | Up | Next Section | Contents

Batch Processing


When displaying a large number of objects, it may be impractical to display all of the data at once. While the approach used in figure 3 is practical for a small group of employees, it is impractical for browsing the employees of a large company.

For this reason, the dtml-in tag provides support for batch processing. Information is displayed in batches. Variables are provided (table 22) to aid in the construction of HTML hyperlinks to other batches.

Batch-processing variables

Name

Description

sequence-query

The original query string given in a get request with the form variable named in the start attribute removed.

sequence-step-size

The batch size used.

previous-sequence

The variable is true when the first element is displayed, and when the first element displayed is not the first element in the sequence.

previous-sequence-start-index

The index, starting from 0, of the start of the batch previous to the current batch.

previous-sequence-end-index

The index, starting from 0, of the end of the batch previous to the current batch.

previous-sequence-size

The size of the batch previous to the current batch.

previous-batches

A sequence of mapping objects containing information about all of the batches prior to the batch being displayed.

next-sequence

The variable is true when the last element is displayed, and when the last element displayed is not the last element in the sequence.

next-sequence-start-index

The index, starting from 0, of the start of the batch after the current batch.

next-sequence-end-index

The index, starting from 0, of the end of the batch after the current batch.

next-sequence-size

The size of the batch after the current batch.

next-batches

A sequence of mapping objects containing information about all of the batches after the batch being displayed.

Attributes of batch objects used when iterating over next-batches and previous-batches variables.

Name

Description

batch-start-index

The index, starting from 0, of the beginning of the batch.

batch-end-index

The index, starting from 0, of the end of the batch.

batch-size

The size of the batch.

The batch-processing facilities of the dtml-in tag are quite powerful, but the various options and approaches are complex. For lucidity, take for example a simple table of 36 words (figure 5). The DTML source in figure 6 is used to display this data. The DTML uses an if tag to test for an empty sequence of words. The actual sequence is named w36 . Inside the if tag, there are three dtml-in tags. All three dtml-in tags include the attributes, size with the value 5 and start with the value qs . The size attribute is used to specify a batch size. For example purposes, the batch size is unusually small. The start parameter is used to specify the name of a variable which holds the index of the first element of the sequence to be displayed. If the variable is not defined, then the first batch is displayed. Figure 7 shows the output of the DTML as displayed on a Web browser for the first two and last two batches.

DTML source to browse 36 words, 5 words at a time

<dtml-var standard_html_header>

<dtml-if w36>

<dtml-in w36 previous size=5 start=qs>
<a href="<dtml-var document_id><dtml-var sequence-query
>qs=<dtml-var previous-sequence-start-number>">
(Previous <dtml-var previous-sequence-size> results)</a>
</dtml-in>

<table border>
<tr><th>WORD</th></tr>
<dtml-in w36 size=5 start=qs>
<tr><td><dtml-var WORD></td></tr>
</dtml-in>
</table>

<dtml-in w36 next size=5 start=qs>
<a href="<dtml-var document_id><dtml-var sequence-query
>qs=<dtml-var next-sequence-start-number>">
(Next <dtml-var next-sequence-size> results)</a>
</dtml-in>

<dtml-else>
Sorry, no words.
</dtml-if>

<dtml-var standard_html_footer>

The output of the DTML source in figure 6 as displayed in a Web browser for several batches.

 

 

 

 

(words 1-5)

(words 6-10)

(words 26-30)

(words 31-36)

The first of the three dtml-in tags is used to display an HTML hyperlink to a previous batch of data. The previous attribute in the dtml-in tag indicates that only previous-batch data should be displayed. Row data are not displayed. If the first batch is being displayed, then no text is inserted (figure 7 (words 1-5)). The source in the first dtml-in tag uses four variable references. The first retrieves the document_id , which is used as a relative URL name for the document. The second variable reference uses sequence-query to retrieve the request query string which has been modified so that it does not include the variable named in the dtml-in tag start attribute, qs . The sequence-query value also contains the necessary punctuation, ` ? ' and ` & ', so that the document_id , sequence-query and URL-encoded value for the next batch start can be concatenated. The URL-encoded value of the next batch start is " qs= " followed by the variable, previous-sequence-start-number . The variable previous-sequence-size provides the size of the previous batch for display in the hyperlink. Note that the previous (or next) sequence size is not necessarily equal to the batch size.

The DTML source has been split over multiple lines by introducing line breaks within var tags. This is a useful way to break up long lines without causing line-breaks to be included in generated HTML.

The second dtml-in tag simply displays the rows in the batch. The third dtml-in tag is similar to the first dtml-in tag, except that a hyperlink to the next batch, rather than the previous batch, is displayed. Table 24 shows the query string, previous batch URL and next-batch URL for the example shown in figure 7.

Query strings and previous batch URL14 and next batch URL for the batches shown in figure 7

Words

Query string

Previous-batch URL

Next- batch URL

1-5

 

 

r36?qs=6

6-10

qs=6

r36?qs=1

r36?qs=11

26-30

qs=26

r36?qs=21

r36?qs=31

31-36

qs=31

r36?qs=26

 

Previous Chapter | Up | Next Section | Contents

SUBSECTIONS