Building Server BehaviorsBuilding Server Behaviors
Tom MuckTom Muck
co-author co-author
Building Dreamweaver 4 Building Dreamweaver 4
and and
Dreamweaver UltraDev 4 ExtensionsDreamweaver UltraDev 4 Extensions
The Dreamweaver The Dreamweaver Extensibility ModelExtensibility Model
• ObjectsObjects• BehaviorsBehaviors• CommandsCommands• Server BehaviorsServer Behaviors• Data SourcesData Sources• ToolbarsToolbars
Server BehaviorsServer Behaviors
• Used to insert code that needs to be processed at the Used to insert code that needs to be processed at the ServerServer
• Important to the integration of custom code into the Important to the integration of custom code into the Dreamweaver environmentDreamweaver environment
• Supported for all of the Dreamweaver Server ModelsSupported for all of the Dreamweaver Server Models
• ASP, PHP, CF, JSP, ASP.NETASP, PHP, CF, JSP, ASP.NET
• Can include one or more modelsCan include one or more models
Constructing Server BehaviorsConstructing Server Behaviors
• Assemble working codeAssemble working code• Build the Server BehaviorBuild the Server Behavior
• Hand CodingHand Coding• The Server Behavior BuilderThe Server Behavior Builder
• Test the Server BehaviorTest the Server Behavior• Package and Distribute the Server BehaviorPackage and Distribute the Server Behavior
The Server Behavior BuilderThe Server Behavior Builder
• Designed to simplify the addition of custom Server Designed to simplify the addition of custom Server BehaviorsBehaviors
• Requires that you know two thingsRequires that you know two things• The final code needed to do the jobThe final code needed to do the job• Where the code needs to goWhere the code needs to go
• Handles the construction of the various functions within Handles the construction of the various functions within a Server Behaviora Server Behavior
• Has significantly increased the number of available Has significantly increased the number of available behaviorsbehaviors
Response.Redirect Server Response.Redirect Server BehaviorBehavior
• Assemble the working codeAssemble the working code• Construct the Server BehaviorConstruct the Server Behavior
• Touring the Server Behavior BuilderTouring the Server Behavior Builder• Testing the Server BehaviorTesting the Server Behavior
• Packaging and Distributing the Server BehaviorPackaging and Distributing the Server Behavior• MXI filesMXI files• MXP filesMXP files• The Dreamweaver ExchangeThe Dreamweaver Exchange
A Conditional Region Server A Conditional Region Server BehaviorBehavior
• More complex codeMore complex code• Requires multiple code blocksRequires multiple code blocks• Can be applied to a variety of objectsCan be applied to a variety of objects• Can be built to check for a number of conditionsCan be built to check for a number of conditions
Part 2Part 2
Going Beyond the Server Behavior Going Beyond the Server Behavior BuilderBuilder
Limitations of the SBBLimitations of the SBB
• Doesn’t provide input validationDoesn’t provide input validation• Creates regular expressions that match the code Creates regular expressions that match the code
exactly -- no fuzzy matches possibleexactly -- no fuzzy matches possible• Doesn’t manipulate the selectionDoesn’t manipulate the selection
SBB-generated Server Behaviors SBB-generated Server Behaviors Can Be ExtendedCan Be Extended
SBB builds HTML, JS, and XML extensionsSBB builds HTML, JS, and XML extensions -- no mystery here. They can be extended.-- no mystery here. They can be extended.
SBB files located in three places:SBB files located in three places: HTML files located in HTML files located in ServerBehaviorsServerBehaviors folder folder XML files located in XML files located in ServerBehaviorsServerBehaviors folder folder Controls located in Controls located in SharedShared > > ControlsControls > >
ScriptsScripts folder folder
Structure of a Server BehaviorStructure of a Server Behavior
initializeIU()initializeIU() -- initializes all controls -- initializes all controls canApplyServerBehavior()canApplyServerBehavior() -- can the SB be -- can the SB be
applied?applied? findServerBehaviors()findServerBehaviors() -- finds instances of the SB -- finds instances of the SB
on the pageon the page applyServerBehavior()applyServerBehavior() -- applies the SB to the -- applies the SB to the
pagepage
A Server Behavior is an HTML document with JavaScript functions, API calls, and XML participants
Structure of a Server Behavior - Structure of a Server Behavior - pt 2pt 2
More API functionsMore API functions
•inspectServerBehavior() -- take the SB apart and populate the interface•deleteServerBehavior() -- delete the SB•analyzeServerBehavior() -- is the SB whole?
API Functions Not ImplementedAPI Functions Not Implemented
copyServerBehavior()copyServerBehavior() pasteServerBehavior()pasteServerBehavior() With these two functions defined in your With these two functions defined in your
SB, you can copy and paste Server SB, you can copy and paste Server Behaviors between pages. Behaviors between pages.
Not implemented, but fully documented in Not implemented, but fully documented in the the Extending DW and DreamweaverExtending DW and Dreamweaver documents.documents.
Input ValidationInput Validation
Generic JavaScript routines can be written to Generic JavaScript routines can be written to use in your extensionsuse in your extensions
Best place to put the validation -- Best place to put the validation -- applyServerBehavior()applyServerBehavior()
Use the Use the errStrerrStr to create an error message -- this to create an error message -- this will stop the SB from being appliedwill stop the SB from being applied
Benefits of validationBenefits of validation Pitfalls of validationPitfalls of validation
Pitfalls of ValidationPitfalls of Validation
ExampleExample: Adding a color to a Server Behavior: Adding a color to a Server Behavior Can your color look like this? Can your color look like this? #00FF00#00FF00
Can your color look like this?Can your color look like this? #00ff00#00ff00
How about this?How about this? RedRed
Pitfalls of ValidationPitfalls of Validation
Or this?Or this? <cfoutput>#Recordset1.UserColorPref#</cfoutput><cfoutput>#Recordset1.UserColorPref#</cfoutput>
Or this? Or this? <%=(rsGetUserPrefs.Fields.Item("bgcolor").Value)%><%=(rsGetUserPrefs.Fields.Item("bgcolor").Value)%>
Answer:Answer: There is no way to validate for every user and every There is no way to validate for every user and every
situation. You can’t predict how someone else will use situation. You can’t predict how someone else will use your extension or how you will use it in the future.your extension or how you will use it in the future.
canApplyServerBehavior() -- canApplyServerBehavior() -- How to Take Advantage of ItHow to Take Advantage of It
What does your SB need as a prerequisite?What does your SB need as a prerequisite? How do you find out if the page has what it How do you find out if the page has what it
needs?needs? Thinking ahead. Can this function come back Thinking ahead. Can this function come back
to haunt you?to haunt you?
Other Dreamweaver Extensions:Other Dreamweaver Extensions:
Server FormatsServer Formats Server ModelsServer Models TranslatorsTranslators ConnectionsConnections Server Behavior Builder ControlsServer Behavior Builder Controls Data SourcesData Sources
Server Formats -- Located in the Server Formats -- Located in the ServerFormats folderServerFormats folder
Adds a format or function to a server expressionAdds a format or function to a server expression Examples:Examples:• Money formattingMoney formatting• Time formattingTime formatting• Removing or replacing charactersRemoving or replacing characters These require that a regular expression to be These require that a regular expression to be
written inside of the written inside of the Formats.xmlFormats.xml file file
TranslatorsTranslators
New format for Dreamweaver MXNew format for Dreamweaver MX Different than Dreamweaver Translators Different than Dreamweaver Translators -- XML architecture-- XML architecture Located in the ExtensionData > MM > Located in the ExtensionData > MM >
Translations folderTranslations folder
ConnectionsConnections
Connections are extensible alsoConnections are extensible also JDBC Drivers can be easily addedJDBC Drivers can be easily added
Server Behavior Builder ControlsServer Behavior Builder Controls
SBB is extensibleSBB is extensible Controls available on the WebControls available on the Web Files located in Files located in
Configuration > Shared > Controls > String Configuration > Shared > Controls > String MenuMenu
Configuration > Shared > Controls > ScriptsConfiguration > Shared > Controls > Scripts
Remember to include the JS file in your Remember to include the JS file in your extensionextension
Data SourcesData Sources
Many possibilities for new extensionsMany possibilities for new extensions• COM objectsCOM objects• CF TagsCF Tags• ASP ObjectsASP Objects• Shopping CartsShopping Carts These are complex extensions tied in with These are complex extensions tied in with
Server Behaviors and CommandsServer Behaviors and Commands