Community TV: Delphi 6 WebSnap with Jim Tierney

By: John Kaster

Abstract: John K interviews Jim Tierney, architect of WebSnap, for the details on this new Delphi 6 feature. Now with text transcript and MP3 audio.

Community TV: Delphi 6 Launch Interviews

Delphi 6 WebSnap with Jim Tierney

WebSnap Architect

Interview by John Kaster, Borland Developer Relations. Jim and John talk about WebSnap, the RAD way to produce full-featured Web server applications in Delphi 6. Topics include Adapters, Active Scripting, XML and XSLT.

You can

  • view the streaming version (26:26),
  • download a zipped AVI (64MB)
  • listen to or download the MP3 audio (10MB)
  • Interview Transcript

    John Hi, this is John Kaster with Developer Relations for Borland and I have with me today Jim Tierney, the architect of WebSnap, which is a new feature in Delphi 6. Hi, Jim.
    Jim Hi, John.
    John WebSnap is brand new. I've never heard of this before Delphi 6, so what's it do?
    Jim Well, first I should tell you what one of our objectives was in developing WebSnap. [It] was to create a system or an environment where we could support a team of developers collaborating on a web application. When we thought about a team, we thought about, not only the Delphi programmer, but also the HTML layout person who might not even know Delphi or Pascal, who's tool choice might be something like Dreamweaver, and who might know JavaScript. We wanted to create a system where the Delphi programmer could work side by side with the HTML layout specialist, working on a project, without getting in each other's way.
    John You just talked about multiple people working together at the same time to build a web application. How did you accomplish this in the Delphi IDE?
    Jim Well, we did two things. We integrated active scripting, so you can use JavaScript to code up the HTML logic to generate a page. Then we added script-enabled components. The Delphi programmer who's familiar with components can essentially use these scriptable components to define, more or less, an interface to their application that the person [who] knows JavaScript can use to generate a page.
    John What kind of active scripting can I do with WebSnap?
    Jim You can use any active scripting engine you want. Microsoft ships JavaScript and VBScript. There are third-party engines available as well, and you can use those with WebSnap. I should mention, however, that certain components that we provide will generate JavaScript for you. When you're using those components, you're going to get JavaScript.
    John Delphi is always known for making the hard things easy. What kinds of things does WebSnap do that make web application development easy?
    Jim One of the things we wanted to do was make it easier to do the "plumbing" of your application, or the "electrical." In other words, there is a lot of coding you typically need to do to handle HTTP, rather than [doing] coding that's about your business logic. We wanted to, as much as possible, do that for you automatically, so you can concentrate on writing your business logic.
    John When you say, "do this for me automatically," how exactly am I going to build this application and have WebSnap take care of how it functions together automatically?
    Jim Let's just take one example. You want to create a new page in your application, okay? With WebSnap, what you do is say, "I want a new page." You'll get a page, and if you just run the application, it will automatically dispatch that page when the URL includes the name of that page. The way this is accomplished is by having a new module type called a web page module that you can create with a wizard. It finds a page and gives it a name. Then there is another component called the page dispatcher that's responsible for examining the HTTP request. When it finds a request for a particular page, it will automatically invoke that page and dispatch the request.
    John You mentioned a page dispatcher component. Are there other new components that are part of WebSnap?
    Jim Yes. We have quite a few new components on the WebSnap palette and a variety of types. We have a session component that can be used to manage end-user login and so forth. We have a web user list that manages a list of user names, passwords, and access rights. We have some new page producer components. We have this new type of component called an adapter.
    John I have a feeling you want me to ask, "What's an adapter?"
    Jim Right. An adapter is a really big part of WebSnap. It makes dynamic data-driven web pages work. It does this by connecting your business logic with the script and with the HTTP request.
    John Could you give me an example of how you use an adapter?
    Jim Okay, John, let's take a dataset adapter. This is one of the components that we have, one of the adapter types, that knows how to expose the fields and some commands on a dataset component. You would drop a dataset adapter on your module and hook it up to a dataset. Then you would need to define how the dataset adapter exposes the dataset. You would add adapter fields to the dataset adapter that are representative of the fields in the dataset. Then you would add components we call "actions" to the adapter that would identify the commands you would like to be able to execute on a dataset. The sort of commands that the dataset adapter supports are delete, edit, next row, apply, those sorts of things.
    John You set up the fields and the actions with this adapter. How does that end up coming out as a web page?
    Jim At this point, you are going to be able to write active script that communicates with the adapter component. The dataset adapter in this case is script-enabled, so you could write script that pulls the field values out of the adapter, and writes them to a web page. You could also write script that pulls parameters needed to execute the actions of the dataset adapter, and write those to a web page. At this point, you would have a web page that displays a form or a grid that shows the data for that adapter (or for the dataset), and can execute the commands on the adapter.
    John What happens when somebody invokes one of these actions like pushing a delete button?
    Jim What happens at that time is, of course, you're going to get an HTTP request coming into your web application as a result of submitting the HTML form. The application is going to look at that request and figure out what to do. The component that is responsible for looking at the request is the adapter dispatcher. The adapter dispatcher will look at the request, and if it finds a request to execute an action within the request, it will find the action component (in this case, it would be the dataset adapter delete row action). It's going to call that action to execute the command. The adapter dispatcher is also going to extract parameters out of the HTTP request, and pass them along to the dataset adapter delete row action.
    John [Suppose] you've figured out that somebody wants to delete a row from the dataset. What actually happens with the WebSnap server?
    Jim The key dataset adapter delete row action needs to restore the state of the web application at this time. WebSnap is slanted toward developing stateless web applications, so we're not keeping track of what happened on the previous page with WebSnap. [We will] always pass enough information to the web page (to the client) so that we can figure out, from what [is] sent to us through a web request, what needs to be done and how to do it. In the case of the dataset adapter, there is going to be some kind of key value that will be passed. It's going to need to locate the record in the dataset using this key value. Then it will call the dataset to do the delete.
    John Does that improve the scalability of the application?
    Jim Yes, it improves the scalability. That's the main reason for doing applications this way.
    John In some of the WebSnap demos that I've looked at, there's tons of graphics all over the place, coming from a variety of sources. How does WebSnap handle these graphics?
    Jim Some of the graphics are dynamic in that they are pulled out of database tables, downloaded on demand, and displayed on a web page. Those are the [graphics] that WebSnap really helps you with. In the case of the dataset adapter, the dataset adapter image field might be used. (In these demos, that is the component we are using to provide the images.) The dataset adapter image field pulls a bitmap out of a blob field in a database column, and, on the fly, converts it to a JPEG. Then it writes the JPEG file out to the HTTP response. This will be sent down, eventually, to the browser, and the browser will be able to display the image.
    John When you want to create a full-featured database web application, one of the hardest things [to do] is to update these graphics or other binary information that is part of that database. Does WebSnap make this easier?
    Jim WebSnap helps you with this. In an application like that, you typically have a form with a file upload field. These fields have a little browse button (this is done automatically by the browser) allowing the user to select a file. When the user clicks the apply button, the file is going to be sent as part of the HTTP request to the web application. WebSnap can automatically pull the file information out of the request, and automatically upload or update the database column with, in this case, a bitmap. The component that does this is, once again, the dataset adapter image field. As well as knowing how to provide an image as part of a response, it knows how to accept an image as part of a request.
    John If I have a form that has two different graphics on it, can I upload both of them at the same time by clicking one apply button?
    Jim You can. In fact, you could upload images at the same time that you update text fields. With this version of our Internet support, we've added support for multi-part forms. You would use multi-part forms when you want to upload different types of data in an HTTP response or request.
    John In WebSnap, when somebody uploads these multiple attachments, how do I get access to them in my code?
    Jim You would access a files property that we have in the web request data structure. This is simply an array of all the files that were uploaded with the request. The elements in the array identify the type of the file, and allow you to get at a stream that contains the actual file.
    John It sounds like you can do quite a bit with the dataset adapter. What other kinds of adapters does WebSnap have?
    Jim On the palette, we have three additional adapters that I should mention. The TAdapter is a very basic adapter that doesn't have any built-in functionality or knowledge like the TDatasetAdapter. With this adapter, you add fields and actions. Then, for each field, you define an event handler that will return the value for that field. For each action, you define an event handler that will execute the action. You use the TAdapter when you have some data that you want to expose through scripting that you can do through event handlers.

    The other one I would like to mention, which is very much like the TAdapter, is the TPageAdapter. This one adds the notion of multiple page support. With this adapter, if you set a property called page size, you can use the adapter to display a page with a limited number of rows (say, you only want 20 rows on a page). You can also add actions that allow you to move between pages. There are some built-in actions: previous page action, go to page action, and next page action.

    Another adapter is the TLoginFormAdapter. [It] has some built-in fields that are used to generate a login page. We have a user name field, a password field, and a next page field. The next page field displays all the pages in the application. When the user logs in, they can indicate which page they want to go to next.

    John If I want to either modify one of the adapters you have or create my own, can I do that?
    Jim You can. One of the reasons you would want to create a new adapter component is that you want support for displaying your data at design time. If you use the TAdapter and define events to access your data, those events are not going to be called when you're in design mode. However, if you define a new adapter component that's in an installable package with built-in support for accessing your data, you'll be able to view the page at design time because we will execute the active script in design mode and give you a preview.
    John WebSnap has a few adapters that ship with it. I can create my own adapters for it. If I want to use your adapters and the adapters I create in the same application, what do I have to do to get the output from all of them?
    Jim We have a new producer component that can be used as an alternative to writing your own script. It's called the AdapterPageProducer, and it automatically generates HTML and JavaScript for you to generate forms and grids on pretty much any adapter. You add components to it (it's a container for components) to build up a hierarchical representation of your form. Depending on the properties you specify for each component in the hierarchy, and the arrangement of the hierarchy, and the type of components in the hierarchy, you will get different sorts of forms. For example, you can use it to generate a grid with buttons on each row that will perform some action, or you can generate a form with buttons to perform actions on the data displayed by that form.
    John What if I want to do something really complex like a grid with multiple master detail records? Can I do that type of thing with this?
    Jim Yes, it supports master detail. You could have a master form and a detail grid on the same page. You could edit detail records and the master record in one request. In other words, you could type something into the master record fields and some of the detail record rows, hit a single reply button, and all the information would be sent to the web application and correctly processed.
    John I'm looking forward to seeing that. What if the user puts in erroneous data, or some other error condition like that happens?
    Jim The adapters have built-in support for capturing errors that occur in the application. An exception occurs, for example, when you are trying to update a database column with the wrong type of data. Let's say you have something that's not a number, and you're trying to update a numerical column. An exception will be raised. The adapter will capture the exception, and make it part of its errors object. When you're writing the script for that page, you will be able to traverse the errors object and display messages to indicate what errors occurred.
    John A little while you back, you mentioned sessions and logins. What other support does WebSnap have for client interaction?
    Jim WebSnap supports the notion of access rights. This allows you to define which users can access adapter fields, adapter actions, or pages that you define in your application.
    John Can you give me an example of how you would use these access rights in a WebSnap application?
    Jim One thing you might want to do is tailor your WebSnap application's appearance to a particular user that is logged in. The way you could do this is by writing script that looks at the user's access rights and generates HTML appropriate for that user. For example, if the user has rights to update a particular field, you could generate HTML to display an input field. If the user has just simple read access, you could generate static text. If the user doesn't even have read access, you could hide the field entirely.
    John We've been talking a lot about the output, and how you can deliver features for your web application. What about when I'm using the designer in the IDE?
    Jim We've added some nice IDE features. One really important feature is syntax highlighting. Now you'll be able to have color-coding on your HTML and XML. This makes it much easier to read.

    The other feature is WebSnap design services, additional views that appear as part of the editor window. There are tabs at the bottom to access these views. We have a number of different views you can use when you're developing web applications. We have a preview. We have HTML result view, which shows you the text that will be sent to the browser. We have HTML script view, which shows you the script and HTML that is generated by a component like the TAdapterPageProducer. We have XML view, which is a read-only tree view of XML. Then we have XSL view, which is a read-only tree view of XSL.

    If you're using the TXSLPageProducer with your web page module, you'll see some different views. You'll see the preview, but you'll also see the XSL view to show you a tree of your XSL, and an XML view to show you a tree of the XML that's being used by the TXSLPageProducer.

    John You just dropped a hint about XSL. Does WebSnap support XML and XSLT?
    Jim Yes. You might want to use XML and XSLT to generate HTML content. It's really an alternative to JavaScript or to transparent tags. To use the XSLPageProducer, you have an XSLT file that you reference from the component, and some XML that comes from the file or from another component. (For example, you can hook an XSL page producer to a DataSnap data packet using an XML broker component.) The XSLPageProducer will perform the transformation for you using XSLT and XML, and generate HTML content.
    John You were talking about using XML that was produced by some components in the WebSnap architecture. What about just using external files?
    Jim We do have some nice support for external files in the IDE. When you open an XMl file, you'll get syntax highlighting and the XML view. This is also true if you open an HTML file — you'll get syntax highlighting and the preview.
    John It sounds like WebSnap was a lot of work. Did you start from scratch?
    Jim No, I didn't. WebSnap builds upon the technology that was originally developed in Delphi 3. We used to call this technology WebBroker, and now we call it NetCLX. This is also the technology that is in Kylix.
    John You explained earlier how I could create my own custom adapters for WebSnap. Did you consider that an important part of the WebSnap architecture?
    Jim Yes, that's a very important part. WebSnap was designed with extensibility in mind. We made it possible to develop new components that can augment WebSnap, or replace some of the components with components that have different functionality. For example, you can develop your own session service. People should also know that WebSnap works with different kinds of files. For example, if somebody wanted to integrate WML support into WebSnap, it would be possible. WebSnap doesn't make any assumptions about the type of template file types that a web page module will use.
    John You've been mentioning the WebSnap wizard every once in a while. How can I add support for my specific stuff that I do to customize WebSnap into the wizard?

    The web application wizard and the web page module wizard can be sensitive to components that you register. For example, the web application wizard gives you the option of selecting various types of components that will be part of your application module, such as session, web user list, application adapter, and so forth. If you register your components that are designed to replace those particular component types, they will appear in the wizard. The user can set up the wizard so, by default, those will be the components they get when they create a new application.

    In the web page module wizard, there is a list of producers that can be associated with that web page module. If you register your producer with WebSnap, it will automatically appear in that list. One of the other things you can do to customize the web page module wizard is register new templates. Templates define HTML or other content that will automatically appear in the new template file you are creating with the wizard. You can have HTML or some other content that you want to use within your application for every page that makes all your pages consistent in appearance.

    John Jim, I want to thank you for the information on WebSnap and your time.
    Jim You're welcome, John.
    John And thank you all for watching.

    Transcript produced by White Tiger Communications

    Legal Notices

    These multimedia files are copyright © 2001 by Borland Software Corporation. All Rights Reserved Worldwide

    All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation, formerly known as Inprise Corporation, in the United States and other countries. Other names mentioned herein may be trademarks of the party using such names. This release contains forward-looking statements. All statements that are not historical are forward-looking. Forward-looking statements may relate to, but are not limited to, Borland's future financial performance, capital expenditures, revenues, acquisitions, earnings, costs, product development plans, global expansion plans, estimated size of potential customer markets, demand for our products, the projected acceptance by existing or potential customers of new technologies and the potential features of, or benefits to be derived from, the products developed, marketed or sold by Borland, market and technological trends in the software industry and various economic and business trends. Such forward-looking statements are only predictions and involve a number of uncertainties and risks that may cause actual events or results to differ materially. Factors that could cause actual events or results to differ materially include, among others, the following: general economic factors and capital market conditions, general industry trends and the potential effects on us of competition in computer software product and services markets, growth rates in the software and professional services markets that we participate in, rapid technological change that can adversely affect the demand for our products, shifts in customer demand, market acceptance of new or enhanced products or services developed, marketed or sold by us, delays in scheduled product availability dates, actions or announcements by our competitors, software errors, reduction in sales to or loss of any significant customers, our ability to successfully integrate acquisitions, any failure by us to protect our intellectual property rights, the dependence of certain of our business units on licenses from third parties, our ability to attract and retain qualified personnel, and other factors described in our latest Annual Report on Form 10-K and our latest Quarterly Report on Form 10-Q filed by Borland Software Corporation with the SEC, copies of which may be obtained from the SEC at Borland undertakes no obligation to update any information contained in this release.

    Server Response from: ETNASC04