Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

Application-Specific Events

Let’s now look at how an application can throw its own application-specific events to customize responses. In the following example, we want to take special action when the boss calls on his cell phone (214.322.6666) and can’t recall the code to access his data.

Listing 5 Using catch to customize the response to user input

1  <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" 
2   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
3   xsi:schemaLocation="http://www.w3.org/2001/vxml 
4    http://www.w3.org/TR/voicexml20/vxml.xsd">
5    
6    
7    <catch event="com.zorkon.bossHasProblem"> 
8      <prompt>Sir, we are so sorry you are having trouble. 
9        Some one will contact you shortly.</prompt> 
10     <submit next="com.zorkon/bossproblem.jsp"/>   
11     <exit/>   
12   </catch>  
13   
14   
15  <form id="getData">
16  
17   <field name="user_id" type="digits"> 
18    <prompt>What is your numeric user I D</prompt> 
19   </field>
20   
21   <field name="password"> 
22    <prompt>What is the code word?</prompt> 
23    <grammar version="1.0" root="root">
24    <rule id="root" scope="public">bingo</rule>
25    </grammar>
26    
27    <nomatch>
28    <if cond="session.callerid == ’2143226666’">
29      <throw event="com.zorkon.bossProblem"/>
30    <else/>
31       <throw event="com.zorkon.userProblem"/>
32    </if>
33    </nomatch>
34    
35   <help>It is the name of a popular multi-player game.</help> 
36   
37   <catch event="noinput com.zorkon.userProblem"> 
38    <prompt>Security violation! You are in big trouble.</prompt> 
39   </catch> 
40   
41   </field> 
42   
43  </form>
44  </vxml>

In Listing 5 we use our prior knowledge of the boss’ phone via the built-in variable session.callerid to decide on which event to throw. We handle a nomatch event (line 27) to catch a grammar input error and then throw one of two application-specific events, com.zorkon.bossProblem (line 29) or com.zorkon.userProblem (line 31 ), depending on whether the call comes in from the boss’ phone or elsewhere. Note that we don’t need to do anything special to create our own application events. All that’s needed is to give a name for the event we want to throw, as in the following:

<throw event="com.zorkon.bossProblem"/>
  • + Share This
  • 🔖 Save To Your Account