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 See DTML source to create an employee phone listing which properly handles the case of no employees by using an in tag with an if tag. is practical for a small group of employees, it is impractical for browsing the employees of a large company.

For this reason, the in tag provides support for batch processing. Information is displayed in batches. Variables are provided (table See Batch-processing variables) 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 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 See Table of 36 words). The DTML source in figure See DTML source to browse 36 words, 5 words at a time 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 in tags. All three 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 See The output of the DTML source in figure 6 as displayed in a Web browser for several batches. 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

<!--#var standard_html_header-->

<!--#if w36-->

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

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

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

<!--#else-->
Sorry, no words.
<!--#/if-->

<!--#var standard_html_footer-->

The output of the DTML source in figure See DTML source to browse 36 words, 5 words at a time 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 in tags is used to display an HTML hyperlink to a previous batch of data. The previous attribute in the 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 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 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 in tag simply displays the rows in the batch. The third in tag is similar to the first in tag, except that a hyperlink to the next batch, rather than the previous batch, is displayed. Table See Query strings and previous batch URL and next batch URL for the batches shown in figure 7 shows the query string, previous batch URL and next-batch URL for the example shown in figure See The output of the DTML source in figure 6 as displayed in a Web browser for several batches..

Query strings and previous batch URL15 and next batch URL for the batches shown in figure See The output of the DTML source in figure 6 as displayed in a Web browser for several batches.

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