When Written: Aug 2007
One AJAX library that I haven’t mentioned yet and nor does the book, and that is ‘Spry’. This is the Adobe AJAX library which I have written about in this column before. Adobe’s documentation is good and it is not too difficult to use this library, however it is a case of adding code manually, or rather was, until now. The latest version of Dreamweaver which is called CS3, in line with the other Adobe products, now has support for the SPRY Framework amongst several other new features. I thought I would take a quick look at a couple of the new features of Dreamweaver that for my money make the upgrade worth the cost. Firstly as I have just mentioned is its support for AJAX in the form of the SPRY Framework. To use these features it’s simply a click on the SPRY tool bar and a dialog box opens up, you simply fill in the details and that is about it, your first bit of AJAX!
So what features does the SPRY Framework give you? Firstly there is a simple collapsible panel which enables content to be hidden on a page which expands out when the user clicks on the top bar of the panel. The content is already on the page so you are not saving anything on the page file size, but it is an interesting way of getting a lot of content into a smaller area of browser space. A slightly more complex version of this which allows multiple areas is the Accordion object. Then there are the inevitable Tabbed panels object and the vertical and Horizontal Menu objects. These menu objects allow you to build dynamic dropdown menus in a very simple way. This, in my book, is greatly preferable to the way that some of the menu builders work. Whilst they are quite flexible and seem to work well, they often generate code which is almost impossible to understand or edit without the builder program. This can give problems integrating it into your web site if others are to edit the content later and may need to edit the menu. The next set of four SPRY objects are validation objects for Form objects and can be used to make sure the user has entered data correctly on a web form.
Obviously this validation should be done server-side once the user clicks on submit and the next web page is called on the server. But it gives a much better user experience if some of the validation is done before the next web page is called; this is called client-side validation. This way the user gets feedback about their entry before they have to wait for the ‘round trip’ of the server getting the next page and they find that they have left something off the form. These SPRY validation controls only allow very basic validation of the; ‘is the text box empty’ type of thing and no tests for valid form of data, for example testing for an email address or numeric data is within range. It is important to still do the validation server-side after the submit button has been clicked because the user’s browser may have Javascript disabled and so the Ajax validation code would not run. The final set of SPRY objects included with Dreamweaver CS3 is used with sets of data and consists of the usual datagrids, connection objects and data repeater areas. These work very well, giving client side sorting and refreshing of the data grids without the whole page being redrawn.
A point worth noting here is that the datasets that these objects expect to work with are XML datasets. The examples provided hold their data in a series of XML files, not really a very convincing demonstration. Let’s face it if you were designing a website with dynamic content, there would be a database somewhere and it is this content you would want to display. So if you wanted to use these objects you would either have to create a web service which would query your database and return an XML data feed or another way might be to use a newish addition to the syntax of SQL Server, which converts any query to produce an XML data stream. Say you wanted the query ‘SELECT * FROM MYTABLE’ to return an XML data stream, then all you need to do is change the query to ‘SELECT * FROM MYTABLE FOR XML AUTO’. Its as simple as that.
Article by: Mark Newton
Published in: Mark Newton