XML
  Home arrow XML arrow Page 6 - XForms Basics, Part 3
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
XML

XForms Basics, Part 3
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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

    - Flex Array Collection Sort and Filtering
    - The Flex Tree Control
    - Flex List Controls
    - Working with Flex and Datagrids
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek