230 likes | 388 Views
Building Server Behaviors Tom Muck co-author Building Dreamweaver 4 and Dreamweaver UltraDev 4 Extensions. The Dreamweaver Extensibility Model. Objects Behaviors Commands Server Behaviors Data Sources Toolbars. Server Behaviors.
E N D
Building Server Behaviors Tom Muck co-author Building Dreamweaver 4 and Dreamweaver UltraDev 4 Extensions
The Dreamweaver Extensibility Model • Objects • Behaviors • Commands • Server Behaviors • Data Sources • Toolbars
Server Behaviors • Used to insert code that needs to be processed at the Server • Important to the integration of custom code into the Dreamweaver environment • Supported for all of the Dreamweaver Server Models • ASP, PHP, CF, JSP, ASP.NET • Can include one or more models
Constructing Server Behaviors • Assemble working code • Build the Server Behavior • Hand Coding • The Server Behavior Builder • Test the Server Behavior • Package and Distribute the Server Behavior
The Server Behavior Builder • Designed to simplify the addition of custom Server Behaviors • Requires that you know two things • The final code needed to do the job • Where the code needs to go • Handles the construction of the various functions within a Server Behavior • Has significantly increased the number of available behaviors
Response.Redirect Server Behavior • Assemble the working code • Construct the Server Behavior • Touring the Server Behavior Builder • Testing the Server Behavior • Packaging and Distributing the Server Behavior • MXI files • MXP files • The Dreamweaver Exchange
A Conditional Region Server Behavior • More complex code • Requires multiple code blocks • Can be applied to a variety of objects • Can be built to check for a number of conditions
Part 2 Going Beyond the Server Behavior Builder
Limitations of the SBB • Doesn’t provide input validation • Creates regular expressions that match the code exactly -- no fuzzy matches possible • Doesn’t manipulate the selection
SBB-generated Server Behaviors Can Be Extended • SBB builds HTML, JS, and XML extensions -- no mystery here. They can be extended. • SBB files located in three places: • HTML files located in ServerBehaviors folder • XML files located in ServerBehaviors folder • Controls located in Shared > Controls > Scripts folder
initializeIU() -- initializes all controls canApplyServerBehavior() -- can the SB be applied? findServerBehaviors() -- finds instances of the SB on the page applyServerBehavior() -- applies the SB to the page Structure of a Server Behavior A Server Behavior is an HTML document with JavaScript functions, API calls, and XML participants
More API functions Structure of a Server Behavior - pt 2 • inspectServerBehavior() -- take the SB apart and populate the interface • deleteServerBehavior() -- delete the SB • analyzeServerBehavior() -- is the SB whole?
API Functions Not Implemented • copyServerBehavior() • pasteServerBehavior() • With these two functions defined in your SB, you can copy and paste Server Behaviors between pages. • Not implemented, but fully documented in the Extending DW and Dreamweaver documents.
Input Validation • Generic JavaScript routines can be written to use in your extensions • Best place to put the validation -- applyServerBehavior() • Use the errStr to create an error message -- this will stop the SB from being applied • Benefits of validation • Pitfalls of validation
Pitfalls of Validation • Example: Adding a color to a Server Behavior • Can your color look like this? #00FF00 • Can your color look like this? #00ff00 • How about this? Red
Pitfalls of Validation • Or this? • <cfoutput>#Recordset1.UserColorPref#</cfoutput> • Or this? • <%=(rsGetUserPrefs.Fields.Item("bgcolor").Value)%> • Answer: • There is no way to validate for every user and every situation. You can’t predict how someone else will use your extension or how you will use it in the future.
canApplyServerBehavior() -- How to Take Advantage of It • What does your SB need as a prerequisite? • How do you find out if the page has what it needs? • Thinking ahead. Can this function come back to haunt you?
Other Dreamweaver Extensions: • Server Formats • Server Models • Translators • Connections • Server Behavior Builder Controls • Data Sources
Server Formats -- Located in the ServerFormats folder • Adds a format or function to a server expression • Examples: • Money formatting • Time formatting • Removing or replacing characters • These require that a regular expression to be written inside of the Formats.xml file
Translators • New format for Dreamweaver MX • Different than Dreamweaver Translators • -- XML architecture • Located in the ExtensionData > MM > Translations folder
Connections • Connections are extensible also • JDBC Drivers can be easily added
Server Behavior Builder Controls • SBB is extensible • Controls available on the Web • Files located in Configuration > Shared > Controls > String Menu Configuration > Shared > Controls > Scripts • Remember to include the JS file in your extension
Data Sources • Many possibilities for new extensions • COM objects • CF Tags • ASP Objects • Shopping Carts • These are complex extensions tied in with Server Behaviors and Commands