Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


The Server Behavior Builder
The Server Behavior Builder

Dreamweaver is at the top of the heap in the arena of Web-development applications. Part of the reason why it is so successful is its plethora of timesaving features that generate code for you. Probably the biggest timesaving feature of all - and the least used tool in the Dreamweaver arsenal - is the Server Bahavior Builder. I'll tell you why in a moment, but first I want to talk to you about your workflow.

Your Workflow in Dreamweaver
Dreamweaver attracts many types of developers and designers by its very nature. The program appeals to designers because of the real-time rendering of the HTML and server-side code in Design view. The program appeals to hand-coders because it allows you to type code in Code view without worrying about the program changing your code. The program appeals to Web application developers because it combines hand-coding, quick application development using built-in behaviors and server behaviors, and offers plit Code/Design view for easy access to all aspects of your page.

The workflow for these developers will vary widely. A hand-coder may never use a behavior or server behavior, and never even open Design view. A person who works in Design view may never edit code by hand.

Different developers have different types of workflow, but the concept of the server behavior can fit into anyone's workflow. This is why: when you build your own server behavior, you are using your code. You aren't using some code written by Macromedia, or someone else's idea of how a particular function or section of code should be written. It is your code, packaged into a point-and-click interface that can be inserted into a document quickly and accurately. You can click a button faster than you can type, copy, or paste. Any code that you find yourself using more than once makes a good candidate for a server behavior.

Isn't a server behavior just like a code snippet? In a way it is, but it is also much more than that. Server behaviors are handy because they are packaged functionality. They exist for the sole purpose of speeding up the development process. One aspect of server behaviors that makes them so useful is that they can consist of more than one code block - often in different parts of your page. For example, if you have a piece of code that generates the recordset, opens a file on the server, attaches the file to an e-mail, sends the e-mail, and then closes a recordset, you might be looking at three or four blocks of code. You can put the whole thing into a server behavior and save the hassle of inserting separate snippets or copying/pasting blocks of code into your page.

The other aspect of server behaviors that truly separates them from the code snippet or the copy/paste method is that they can be parameterized. The parameters can be typed in or you can use any of the built-in Dreamweaver controls, such as browse buttons for files; buttons for database fields; or dropdown lists of connections, database tables, or fields. The advantage here is that you can allow Dreamweaver to choose an item so that you don't risk mistyping a field name, or need to calculate relative paths to documents and images.

Now that you know why you should build your own server behaviors, let's get down to building one. Because Dreamweaver supports a wide variety of server environments, I'll show the code for each of the server environments that you can use with Dreamweaver.

Building a Server Behavior
Not much skill is involved in building server behaviors. The biggest hurdle is changing your workflow to incorporate the Server Behavior Builder (SBB) into it. To build one, you need to know only two things: the code you want to insert in the page, and where you want to insert it. The Server Behavior Builder does the rest for you, with its wizard-like interface. After you've built the server behavior, it will be available to you from the Server Behaviors panel.

The SBB is located in the Server Behaviors panel. To access it, click the plus sign (+) on the panel and then click New Server Behavior (see Image I). This will open up the builder. To get the ball rolling, we'll create a very simple server behavior that redirects a user to a different page if a session variable is not equal to a specific value. Use Code I for the server model of your choice to complete the example. For the examples I'm going to assume that you already have a site set up in the server model of your choice.

After clicking New Server Behavior, you are presented with the dialog box in Image II. Follow these simple steps to create the server behavior.

  1. Pick the language your page uses from the dropdown list. The dropdown list should already be showing the server language of your page, but if it isn't, choose it. Dreamweaver supports these languages:
    - ASP/JavaScript
    - ASP/VBScript
    - ASP.NET VB
    - ASP.NET C#
    - PHP MySQL
    - ColdFusion
    - JSP
  2. Give your server behavior a name. Call this one "Redirect On Session Value". The hardest part of building a server behavior is giving each server behavior a unique name that is 27 characters or less, and make it meaningful to you.
  3. Click OK to move to the next dialog box, shown in Image III. Here is where you will add the code for your server behavior. So far, creating the server behavior has been a lot like creating a snippet.
  4. Click the plus sign to insert a new code block. The code block will have an arbitrary name, like "Redirect On Session _block1", which you can accept by clicking OK or change it to something else. In most cases, the default name is fine, as it is a name that Dreamweaver will use internally to keep track of the code blocks. The only consideration is that the name has to be less than 26 characters if you want to package your server behavior. Unfortunately, Dreamweaver does not enforce this internally. In this case, remove all the spaces so that it reads "RedirectOnSession_block1". That will make the name 24 characters. Click OK to accept the name.
  5. Next you can paste your code into the Code Block box. The box will have some generic text in it to begin with that says "Replace this text with the code to insert when the server behavior is applied". This is exactly what you should do. Paste the code from Code I into the box.
  6. In Code I notice that the code has three items that can be variables: the name of the session variable (SessionVarName), the value that you want to match (ValueToMatch), and the page that you will be redirecting the visitor to (PageToRedirect). Replace these now by highlighting each word in turn, then clicking the Insert Parameter In Code Block button. That brings up the dialog in Image IV.
  7. The name of the parameter should be changed from the generic "Param1" to something meaningful. In this case, the name you use will show up in your final server behavior interface. Type "Session Variable Name" for the first parameter, "Value To Match" for the second parameter, and "Page To Redirect To" for the third parameter. Notice that Dreamweaver inserts two @ symbols around your parameter (@@Session Variable Name@@). Dreamweaver uses this pattern internally to replace your parameters.
  8. Choose where you want the code inserted. There are several options here, but we'll choose "Above the HTML Tag" under the Insert Code option, and "The Top of the File" under the Relative Position option.
  9. Click the Next button to move to the next section, where you will create the interface for your server behavior. You can use plain text fields for the Session Variable Name and Value To Match fields, but choose the URL Text Field for the Page To Redirect To field (see Image V). This will place a browse button next to the field so that you can choose a file in your site. Dreamweaver will calculate the relative paths.
  10. Click OK to complete your first server behavior. It will show up now in the Server Behaviors panel.
Choose the new server behavior "Redirect On Session Value" from the panel to see the interface you just created. It should look like Image VI. If you fill in the values and apply it to the page, the code will be inserted at the top of your page.

A More Complex Server Behavior
The first server behavior was really basic, to get your feet wet with the SBB. Now we'll add a slightly more complex server behavior to your collection. This code will work with a search/results page, giving you a keyword highlight on your search word. The code has to be versatile enough to recognize the case of the letters in the search word. For example, if you type "ColdFusion" or "coldfusion" you want the word to be highlighted in the search results using the same case as appears in the text rather than using the case that was typed in the box. Code II will accomplish this.

To build this server behavior we'll follow the exact same steps as before, only this time we have two code blocks to add to the server behavior. The first code block will be a function that is added to the top of the document (with no parameters) and the second block will be added at the current cursor location and will replace whatever is selected. We'll use this to display a recordset field - with the function call already in place.

Following are the steps to build this server behavior:

  1. Choose New Server Behavior from the Server Behaviors panel.
  2. Pick the language that your page uses from the dropdown list.
  3. Give your server behavior a name. Call this one "Highlight Search Word".
  4. Click OK to move to the next dialog box.
  5. Click the plus sign to insert a new code block. The code block will have an arbitrary name. Click OK to accept the name.
  6. Next, paste the code from Code II into the Code Block box. Start with Block 1. This block has no parameters.
  7. Click the plus sign to insert a new code block. The code block will have an arbitrary name. Click OK to accept the name. This is Block 2.
  8. In Code 2, Block 2, the code has three things that will be variables: the name of the recordset (rs), the recordset field (field), and the search field name (searchfield). Replace these now by highlighting each word in turn, then clicking the Insert Parameter In Code Block button.
  9. Type "Recordset Name" for the first parameter, "Field" for the second parameter, and "Search Field" for the third parameter.
  10. The next step is to choose where you want the code inserted. You will have to choose a position for each code block. Choose "Above the HTML Tag" under the Insert Code option, and "The Top of the File" under the Relative Position option for the first code block (the function). Choose "Relative to the Selection" and "Replace the Selection" for the second code block.
  11. Click the Next button to move to the next section, where you will create the interface for your server behavior. Using the arrows, move Recordset Name to the top and Field to the second position.
  12. Choose Recordset Menu for the Recordset Name parameter, Recordset Field Menu for the Field parameter, and leave the Search Field parameter set to a plain text field. Your server behavior interface will now show a dropdown list of all recordsets on the page, and after the user chooses a recordset, it will show all fields in that recordset.
  13. Click OK to complete the server behavior. It will show up now in the Server Behaviors panel.
Tip: One of the first things you should learn about building server behaviors is that you want your code to be solid and completely debugged before you build it as a server behavior.

Using the Server Behavior
Now let's set up a page where you can use this new server behavior. The basic structure of a search/result page is to have a search box and button, a recordset, and a dynamic table that displays the results. To set this page up, we'll use some built-in Dreamweaver server behaviors (using a sample database of your choice). We'll build the entire page from Design view.

  1. Build a form on your page using a text field and a submit button. The easiest way to do that is to open the Form tab of the Insert bar and click the following three buttons in turn: Form, Text Field, Button. Give your text field the name searchfield and set the method of the form to GET.
  2. Add a recordset to your page that is filtered by the text field. A recordset can be added from either the Bindings panel or the Server Behaviors panel, among other places. For this simple demonstration, choose any two fields in your database for the result, and filter one of them by the text field named searchfield.
  3. Add a table to the page to display the results. To do this, open the Common tab of the Insert bar and click the Table icon. Give your table one row and two columns. Put your cursor in the second cell of the table.
  4. Open the Server Behaviors panel and find your new server behavior - Highlight Search String (see Image VII). Choose the recordset and database field that you are searching. Fill in the name of the text field. Click OK. Your new server behavior should be displayed in the server behaviors panel.
  5. Finally, add a Repeat Region server behavior to the table row. The easiest way to do this is to select the <tr> tag in the tag selector at the bottom of the document in Code view, then click the Repeat Region button on the Application tab of the Insert bar.
At this stage you should have a complete working search/results page with custom text highlighting. If you open the page in Code view, you can see the code that has been inserted by each of the server behaviors, including the custom server behavior you just built.

Another great thing about server behaviors is that after you have inserted them into the page, you can call up your interface at any time in the Server Behaviors panel and edit your parameters. As you build more complex code snippets and convert them to server behaviors, you'll soon find this method easier than modifying the code by hand.

Packaging Your Server Behaviors
Server behaviors can be packaged as extensions, giving you an easy way to install your server behaviors onto another computer, or to share among your fellow programmers. Unfortunately, Macromedia did not provide an automated method of packaging server behaviors after you've built them with the SBB. Creating an extension package is easy, however, and a matter of simply writing a small XML file and using the Extension Manager to package the files.

The XML file is stored with an .mxi file extension, which stands for Macromedia Extension Information. The file for the Redirect On Session Value server behavior is shown in Code III. To package the extension, simply put the .mxi file into a folder with the files that were generated by the SBB and double-click the .mxi file to open the Extension Manager. The Extension Manager is like a zip program - it zips all the files into a package along with path information. Double-clicking on an extension package will install the extension into Dreamweaver.

The SBB generated three files - an HTML file that contains the server behavior interface, an EDML file that contains information about the extension, and an .edml file that contains the code block that will be inserted into the document. The three files will be located in the Dreamweaver Configuration folder. In most modern operating systems, the folder will be located in the local multi-user folder. For example, on Windows XP, the folder is located here by default: C:\Documents and Settings\[your username]\Application Data\Macromedia\Dreamweaver MX 2004\Configuration\ServerBehaviors\ASP_VBS.

Conclusion
If you followed the exercises, you have successfully become a Dreamweaver extension writer, but more important, you've added a new tool to your arsenal that should significantl speed up your workflow. Server behaviors are powerful because they insert large blocks of interrelated code into your document, with user-defined parameters presented in an easy-to-use interface. The Server Behavior Builder is a tool that can increase your workflow by speeding up repetitive tasks and making code modifications quickly and accurately using a visual interface.

About Thomas Muck
Tom Muck is coauthor of three UltraDev books including the bestseller, Dreamweaver UltraDev4: The Complete Reference. He is an extensibility expert focused on the integration of Macromedia products with ColdFusion and other languages, applications, and technologies. Tom has been recognized for this expertise as the 2000 recipient of Macromedia's Best UltraDev Extension Award. He also authors articles and speaks at conferences on this and related subjects. As Senior Applications Developer for Integram in Northern Virginia, Tom develops back-end applications for expedited, electronic communications. Tom also runs the Basic-UltraDev site with co-author Ray West.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Please help me, Iam searching for SBB manual and teheres nothing about them 100 places in tne net, including macromedia ... how Do I set Radio Group parameter in a behavior, I do all about the first stage, then when asked for parameters I want one of them be a radio group, How is taht set?, only shows two blank labels Thanks


Your Feedback
oscar duron wrote: Please help me, Iam searching for SBB manual and teheres nothing about them 100 places in tne net, including macromedia ... how Do I set Radio Group parameter in a behavior, I do all about the first stage, then when asked for parameters I want one of them be a radio group, How is taht set?, only shows two blank labels Thanks
Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE