beautypg.com

Adobe Dreamweaver CC 2014 v.13 User Manual

Page 551

background image

<@ loop (@@param1@@,@@param2@@) @> code

block<@ endloop @>

When creating server behaviors, you can use looping constructs to repeat a code block a specified number of times.

<@ loop (@@param1@@,@@param2@@,@@param3@@,@@param_n@@) @> code block

<@ endloop @>

The loop directive accepts a comma-separated list of parameter arrays as arguments. In this case, parameter array arguments allow a user to
supply multiple values for a single parameter. The repeating text is duplicated n times, where n is the length of the parameter array arguments. If
more than one parameter array argument is specified, all the arrays must have the same length. On the ith evaluation of the loop, the ith elements
of the parameter arrays replace the associated parameter instances in the code block.

When you create a dialog box for the server behavior, you can add a control to the dialog box that lets the page designer create parameter arrays.
Dreamweaver includes a simple array control that you can use to create dialog boxes. This control, called Text Field Comma Separated List, is
available through the Server Behavior Builder. To create user interface elements of greater complexity, see the API documentation to create a
dialog box with a control to create arrays (a grid control, for example).

You can nest any number of conditionals or a loop directive within a conditional directive. For example, you can specify that if an expression is true
to execute a loop.

The following example shows how such repeating code blocks can be used to create server behaviors (the example is a ColdFusion behavior used
to access a stored procedure):

datasource=#MM_connection_DSN#

username=#MM_connection_USERNAME#

password=#MM_connection_PASSWORD#>

cfsqltype="CF_SQL_INTEGER">

cfsqltype="CF_SQL_VARCHAR">

In this example, the CFSTOREDPROC tag can include zero or more CFPROCPARAM tags. However, without support for the loop directive, there
is no way to include the CFPROCPARAM tags within the inserted CFSTOREDPROC tag. If this were to be created as a server behavior without
the use of the loop directive, you would need to divide this example into two participants: a main CFSTOREDPROC tag, and a CFPROCPARAM
tag whose participant type is multiple.

Using the loop directive, you can write the same procedure as follows:

datasource=#MM_@@conn@@_DSN#

username=#MM_@@conn@@_USERNAME#

password=#MM_@@conn@@_PASSWORD#>

<@ loop (@@paramName@@,@@value@@,@@type@@) @>

dbvarname="@@paramName@@"

value="@@value@@"

cfsqltype="@@type@@">

<@ endloop @>

Note: New lines after each “@>” are ignored.

If the user entered the following parameter values in the Server Behavior Builder dialog box:

procedure = "proc1"

conn = "connection1"

paramName = ["@CategoryId", "@Year", "@ISBN"]

value = ["#Form.CategoryId#", "#Form.Year#", "#Form.ISBN#"]

type = ["CF_SQL_INTEGER", "CF_SQL_INTEGER", "CF_SQL_VARCHAR"]

The server behavior would insert the following run-time code in the page:

datasource=#MM_connection1_DSN#

username=#MM_connection1_USERNAME#

password=#MM_connection1_PASSWORD#>

cfsqltype="CF_SQL_INTEGER">

544

This manual is related to the following products: