Subdialogs
(Continued from Part 1)
To call this subdialog from the main form, we would use something like this:
What toppings would you like?
Your pizza will have
|
Note that we're using the 'cond' attribute to call this only if the caller wants a pizza. In addition, you can see that we're generating prompts, and make use of the element when the subdialog returns. We make use of the results as shown in the element, by referring to a property of the named object toppings.
In this example, we've referenced a subdialog that happens to be on the same page, but it could just as easily be on a separate page, or be dynamically generated by a server-side program, based on a set of parameters passed in a namelist to the subdialog. Although this is a simple example, you could consider extending the toppings dialog as follows:
- Generate the dialog dynamically based on what's being ordered; provide topping lists for salads, hamburgers, and so on;
- Extend the subdialog such that it accepts customizable prompts as part of the parameter list;
- Have the subdialog return the parameter list in an ECMAScript array or other data structure.
Be sure to download the complete pizza page.
Traps and Pitfalls
The unwary should watch out for a few things related to subdialogs. Here are some tips and tricks:
- Subdialogs execute in a new VoiceXML context; this means it will need to explicitly return anything you want to get back from the subdialog;
- Parameters to the execution of the subdialog must be passed as , while parameters to the generation of the subdialog, are passed in the namelist;
- Remember that you need to refer to the return results as properties of the returned object;
- When designing your application, take a few moments and plan for reusability. If there are dialog elements that might be of use in a reusable form, don't just put them in subdialogs, parameterize them with sensible defaults.
Summary
Subdialogs provide ways to structure your VoiceXML application, and can pave the way to reuse of dialog components within your organization. To get some ideas regarding reusable dialog components, have a look at the components provided by the major speech application vendors. You might also want to have a look at VoiceXML in the Large, the First Words column from March of 2000 for some other ideas regarding structuring your application.
What's Next?
Next month, we're going to provide a list of VoiceXML resources for you to leverage for your speech application.
If there are particular things you'd like to see covered in a future First Words column, drop me a line at , and I'll try to write about it.
back to the top
Copyright © 2001-2002 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE Industry Standards and Technology Organization (IEEE-ISTO).
|