XML
  Home arrow XML arrow Page 6 - XForms Basics, Part 3
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XForms Basics, Part 3
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2004-01-19

    Table of Contents:
  • XForms Basics, Part 3
  • Operating with Extreme Caution
  • Money, Money, Money
  • Shop 'till You Drop
  • The Bookworm Turns
  • An Event to Remember
  • Link Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    XForms Basics, Part 3 - An Event to Remember
    (Page 6 of 7 )

    It was the introduction of events in client-side scripting languages like JavaScript and VBScript that brought about the rise of the dynamic Web site. However, inconsistencies in implementation across browsers meant that developers had to grapple with multiple lines of code to make Web sites cross-browser compatible. XForms has put an end to this misery, at least so far as form events are concerned.

    The XForms 1.0 specification divides the process of event handling into four phases:

    Initialization: This is the very first stage, wherein the XForms processor "wakes up" and begins construction of the data model using the instance data provided. This is also the stage where all relevant XML Schemas are loaded, and all form controls (with their associated bindings) are initialized.

    Interaction: Interaction events are fired as a result of action from the user - for example, keyboard navigation to a new input control, mouse clicks, data entry or item selection. A number of different events can occur in this phase, and each one has a default action associated with it.

    Notification: Notification events don't usually have a default action associated with them; rather, they're triggered as a result of a change in the form state, such as a form control receiving focus or a button being clicked.

    Error handling: These events occur due to errors in XForm processing, such as illegal binding expressions or illegal XPath references. Errors may be either fatal or non-fatal, depending on their severity.

    OK, now enough of the theory. Let's look at a simple example:

     
    <!-- define the form model --> 
    <xforms:model id="bankAccount"
     
    <xforms:instance
      
    <account
       
    <openingBalance>10000</openingBalance
       
    <withdrawal /> 
       
    <closingBalance /> 
      
    </account
     
    </xforms:instance>
     <
    xforms:bind id="nodeClosingBalance" 
    nodeset
    ="/account/closingBalance" /> 
    </
    xforms:model>
    <!-- 
    define the form interface --> 
    <xforms:input id="txtwithdraw" ref="/account/withdrawal"
     
    <xforms:label>Amount to withdraw</xforms:label
     
    <xforms:hint>Please enter the amount you wish to
     withdraw
    </xforms:hint
    </xforms:input>
    <
    xforms:trigger
    <xforms:label>Calculate Closing Balance</xforms:label
    <xforms:setvalue ev:event="DOMActivate" 
    bind
    ="nodeClosingBalance" 
    value
    ="/account/openingBalance - /account/withdrawal" />
    </xforms:trigger

    By definition, the <xforms:trigger> element is the XForms counterpart of the regular HTML form button. When clicked, it generates a DOMActivate event, which is a catch-all event type fired whenever any event (pressing a button, selecting an option) occurs. The <xforms:setvalue> element, which is used to set the value for a particular node after computing it from an XPath expression, listens for this event and acts when it receives it. In this case, the action involves subtracting the withdrawal amount from the opening balance to obtain a new closing balance.

    A number of other event types are available in the XForms model - you've already seen one of the other important ones, the xforms-submit event, in the previous segment of this tutorial. There are too many to list here, so you should take a look at the specification (and the excellent examples included within it), to better understand this topic.

    More XML Articles
    More By Harish Kamath, (c) Melonfire


     

       

    XML ARTICLES

    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway