Plands.com Logo  Business Internet Services 
Main Menu
Home
Planetary CRM
  Benefits
  Features
  Demo
E-Mail Services
  E-mail Hosting
  Newsletters
  Discussion Lists
Web Hosting
Server Co-location
and Administration
Web Applications
Technical Support
Contact Us
DXP Samples
 
DxpHome  ||   Samples  ||   Details  ||   Docs  ||   Trees  ||   xml-xsl  ||   Links
// LoopSetIterator.java

LoopSetIterator encloses two more LoopSet tags and is used to alternately print sets of rows from each LoopSet so that records from all the sets are co-mingled in the final output. For example, the first LoopSet may only refer 1 record. The second LoopSet may have 4 records and require each iteration to print the next 2 rows. The LoopSetIterator will run 2 iterations to print all the rows from LoopSet2. Since LoopSet1 only contains 1 record it will be repeated.

Each LoopSet must have a rowspec attribute which is a parameter name that will return an int[][] from the request at runtime. This contains the information needed by the iterator to print the rows of each set in the proper sequence. See the exec() method below for more information on how this is done.

A LoopSetIterator might be used to print an order form that shows lineitems (ordered by item type) with a subtotal below each group of common items. The lineitems would come from one recordset and be printed by the first LoopSet. The subtotals would come from a second recordset and be printed by the second LoopSet.

Here is an example. Suppose that set1 contains records that are grouped by item category and set2 contains records that subtotal for each category. The LoopSetIterator will do this: LoopSet1 print typeA items (perhaps rows 0,1,2) LoopSet2 print subtotal for typeA (row 0) LoopSet1 print typeB items (perhaps rows 3,4,5,6) LoopSet2 print subtotal for typeB (row 1) ... LoopSet1 print typeN items LoopSet2 print subtotal for typeN

Here is an exmaple of the syntax:

  
<table>
   <tr><th>Item</th><th>Cost</th></tr>
   <dxp:LoopSetIterator>
      <dxp:LoopSet matrix="lineitems" rowspec="itemspec">
         <tr><td><dxp:Index>0</dxp:Index></td><td><dxp:Index>1</dxp:Index></td></tr>
      </dxp:LoopSet>
      <dxp:LoopSet matrix="sutotals" rowspec="subspec">
        <tr><td colspan="2"><dxp:Index>0</dxp:Index></td></tr>
      </dxp:Loopset>
   </dxp:LoopSetIterator>
</table>

Some applications will use an XSL stylesheet to control the output format and others may require data to be structured inside custom tags. Here is a hypothetical example using custom tags to structure the output:

  
 <order>
   <dxp:LoopSetIterator>
      <item-group>
         <dxp:LoopSet matrix="lineitems" rowspec="itemspec">
            <lineitem>
               <item-name><dxp:Index>0</dxp:Index></item-name>
               <item-cost><dxp:Index>1</dxp:Index></td></item-cost>
            </lineitem>
         </dxp:LoopSet>
         <dxp:LoopSet matrix="sutotals" rowspec="subspec">
            <subtotal><dxp:Index>0</dxp:Index></subtotal>
         </dxp:LoopSet>
      </item-group>
   </dxp:LoopSetIterator>
</order>

The active dxp tags will produce output but their tagnames will disappear in the final output. The passive tags (those not registered with the DxpBuilder as a namespace tag) will be inserted each time their enclosing loop is executed.

When the LoopSetIterator iterates through it's enclosed tags it only calls the first level of children by passing the request the first child and then to it's siblings. Active tags inside a LoopIterator are responsible for passing the request to their own children. The LoopSet does this so it can nest other active tags. Passive tags can be nested in the normal manner because they are just saved as char data when the page is compiled.


@author Mark Ashworth
@version 0.1, 2001-04-09

Return to Index

Note: We have tried to test all of the code examples but they may contain errors. Any questions, comments, suggestions, or problems should be sent to info@plands.com.