Effectively using conditional expressions

Effectively using conditional expressions

When using if, else, and elseif directives within the insertText XML tag, the participant text is preprocessed to resolve the if directives and to determine which text to include in the result. The if and elseif directives take the expression as an argument. The condition expression is the same as that for JavaScript condition expressions, and can also contain server behavior parameters. Directives such as this allow you to choose between alternative code blocks based on the values of, or relationships between, server behavior parameters.

For example, the following JSP code comes from a Dreamweaver server behavior that uses the conditional code block:

@@rsName@@.close();
<conditional_code>
@@rsName@@_hasData = @@rsName@@.next();

If the server behavior uses a normal recordset, the <conditional_code> placeholder is replaced with:

@@rsName@@ = Statement@@rsName@@.executeQuery();

If the server behavior uses a recordset from a callable object, it uses the following code instead.

@@callableName@@.execute();


@@rsName@@ = @@callableName@@.getResultSet();

If the server behavior is added for a callable object, the user would enter a value for the @@callableName@@ parameter in the server behavior’s Parameter dialog box. Otherwise, the @@callableName@@ parameter would be empty. Thus, you can rewrite the previous insert text using @@callableName@@ as the if argument. In this example, if the @@callableName@@ parameter is supplied with a value, and first conditional code block (containing the getResultSet() method) is selected:

@@rsName@@.close();
<@ if (@@callableName@@ != '') @>
@@callableName@@.execute();
@@rsName@@ = @@callableName@@.getResultSet();@ else @>
@@rsName@@ = Statement@@rsName@@.executeQuery();
<@ endif @>
@@rsName@@_hasData = @@rsName@@.next();


Getting Started with Dreamweaver
Dreamweaver Basics
Working with Dreamweaver Sites
Laying Out Pages
Adding Content to Pages
Working with Page Code
Preparing to Build Dynamic Sites
Making Pages Dynamic
Defining Sources of Dynamic Content
Developing Applications Rapidly