Updating server behaviors

Replacement update By default, participant EDML files do not have an <updatePatterns> tag, and instances of the participant are updated in the document by replacing them entirely. When a user edits an existing server behavior and clicks OK, any participant that contains a parameter whose value has changed is removed and reinserted with the new value in the same location.

If the user customizes participant code in the document, the participant might not be recognized if the search patterns look for the old code. Shorter search patterns can let the user customize the participant code in their document; however, updating the server behavior instance can cause the participant to be replaced, which loses the custom edits.

Precision update In some cases, it can be desirable to let users customize the participant code after it is inserted in the document. This situation can be achieved by limiting the search patterns and providing update patterns in the EDML file. After you add the participant to the page, the server behavior updates only specific parts of it. The following example shows a simple participant with two parameters:

<% if (Recordset1.EOF) Response.Redirect("some_url_here") %>

This example might use the following search patterns:

<quickSearch>Response.Write</quickSearch><searchPatterns whereToSearch="directive"> <searchPattern paramNames="rs,new__url"> /if\s*\((\w+)\.EOF\)\s*Response\.Redirect\("([^\r\n]*)"\)/i </searchPattern></searchPatterns>

The user might add another test to a particular instance of this code, as shown in the following example:

<% if (Recordset1.EOF || x > 2) Response.Redirect("some_url_here") %>

The search patterns fail because they are looking for a parenthesis after the EOF parameter. To make the search patterns more forgiving, you can shorten them by splitting them up, as shown in the following example:

<quickSearch>Response.Write</quickSearch><searchPatterns whereToSearch="directive"> <searchPattern paramNames="rs">/(\w+)\.EOF/</searchPattern> <searchPattern paramNames="new__url"> /if\s*\([^\r\n]*\)\s*Response\.Redirect\("([^\r\n]*)"/i </searchPattern></searchPatterns>

These shortened search patterns are flexible, so the user can add to the code. However, if the server behavior changes the URL, when the user clicks OK, the participant is replaced, and the customizations are lost. To update more precisely, add an updatePatterns tag that contains a pattern for updating each parameter:

<updatePatterns> <updatePattern paramNames="rs">/(\b)\w+(\.EOF)/¬ </updatePattern> <updatePattern paramNames="new__url"> /(Response\.Redirect\(")[^\r\n]*(")/i </updatePattern></updatePatterns>

In update patterns, the parentheses are reversed and are placed around the text before and after the parameter. For search patterns, use the textBeforeParam(param)textAfterParam parameter. For update patterns, use the (textBeforeParam)param(textAfterParam) parameter. All the text between the two parenthetical subexpressions is replaced with the new value for the parameter.