TOP LINKS YOU MUST CLICK ON


Perfect Partner for Web Services: Getting to Know XForms
Find out about XForms and why they are the perfect partner for Web Services

Digg This!

Page 2 of 2   « previous page

XForms events and actions can be combined to do some of the following:

  • Display a message to the user with varying degrees of intrusiveness ranging from modal dialog boxes to fleeting tool tips
  • Change some value in the instance document
  • Dynamically insert or delete line items in tables
  • Navigate to a new URI, possibly in a new window and possibly replacing the active form
  • Submit all or part of an XML instance document
  • Toggle between different component renderings to implement multi-stage forms or tabbed applications
Introduction to Amazon Web Services
To demonstrate some of the features of XForms and how well suited they are to Web services, I've created a simple form (Listing 3) that uses an Amazon.com Web service to provide a simple book search facility.

As some background, Amazon Web services were launched in mid-2002 as a way of allowing their business partners to create their own content-rich applications based on Amazon's product and pricing information and e-commerce model. Amazon now offers a range of Web services, including access to Web site information and traffic history charts (Alexa Web Information Service) and a distributed message queue service (Amazon Simple Queue Service). Check out the Amazon Web service references in the Resources section for details about all of Amazon's Web services.

For the XForms here, I'll be using the primary Amazon E-Commerce Service (ECS), version 4.0. The ECS exposes 18 methods that allow developers to search for Amazon and third-party product and seller information; details about customer content such as reviews, wish lists, and listmania lists; and to manage shopping carts of products for purchase through Amazon. If you would like to implement this XForms, you will need to create a free Amazon Web services account. Besides giving you access to forums, blogs, code samples, and a technical library, you will also receive an Access ID Key, which is a 20-character code that must be included as a parameter for each Web service call to uniquely identify the caller.

While it's free to use the ECS, there is a restriction that requests should be limited to no more than one per second. The licensing agreement gives the fine detail and other restrictions.

Building and Running the Web Service Client
Creating an XForms Web service client involves defining a SOAP payload as the XForms model, populating this via the XForms user interface controls, and then submitting the payload to a Web service endpoint. When the Web service response is received it can be processed using XPath or XSLT.

Listing 3 shows an XForms model that contains a SOAP payload that initiates one of the most common ECS requests, an item search. Besides the mandatory Amazon Access Key ID, nearly all of the parameters for an item search are optional, so only the absolute minimum needs to be submitted. For this particular XForms, users will be able to search Amazon for books based on keyword, author, and title criteria, so these elements are included in the SOAP payload. The SearchIndex element contains a value of Books meaning the search will target only books, but this could easily be broadened to cover all product types. In addition, the results of a search can be sorted according to relevance, price, or title. This sorting happens on Amazon's side before the Web service response is returned, so it's one fewer processing activity for the client. The Availability, Condition, and MerchantID have been pre-filled with values that should return the widest range of search items. Finally, the ResponseGroup indicates what and how much information will be returned. For an item search and a ResponseGroup value of Medium, this will include full product and pricing details, links to images, and editorial reviews.

Figure 2 shows the XHTML document in Listing 3 open in Internet Explorer.

The search criteria entered by the user populates the XForms model (the SOAP payload) by way of XPath expressions in the body of the XHTML document. Following recommended XForms practice, only enough host language markup is used to correctly position the XForms components, and any styling is handled by an external cascading style sheet (Listing 2).

Once the XForms model has been populated, it is be submitted to the ECS endpoint (shown in the submission element) just like any other Web service payload. The submission element wraps around a toggles element, which switches to the response user interface when the Web service response is ready (Figure 3).

Again, XPath is used, this time with output elements, to extract the necessary information from Web service response payload for display to the user. Notice the repeat element in the responseGUI case element: this simply iterates over a homogeneous collection of nodes from the Web service response, in this case creating a table-like display.

The Search Again button then resets the XForms and the search can be performed again.

Conclusion
HTML forms have long been a standard part of Web development, but they are showing their age when confronted with omnipresent XML, the almost irresistible rise of Web services, and more demanding user-interface requirements (Sidebar 2).

The simple Web service client demonstrated here only hints at the advantages XForms offer over HTML forms. In reality, XForms are a powerful tool for building device-independent, declarative, form-based applications that don't need scripting or programming to deliver rich user interfaces. More important, when compared to other ways of creating Web service clients such as using the SOAP APIs, the XForms alternative is concise and comes with a built-in means of getting a window onto the request and response payloads.

Even so, creating XForms is not as simple as defining tags in an XHTML page. The development model provides a sometimes daunting range of possibilities, and until XForms engines are more widely supported, developers need to critically consider how they will deliver XForms functionality to their clients.

Still, the benefits of using XForms more than balance this effort.

References

  • Amazon Web Services: www.amazon.com/gp/aws/landing.html
  • Dubinko, M. XForms Essentials. O'Reilly & Associates, 2003.
  • Halstead, P., Blain, M., and Manava-Teredesai, V. Developing Solutions with Microsoft InfoPath. Microsoft Press, 2005. If you are looking at a range of form-based technologies besides XForms, it might be worth evaluating InfoPath 2003 to see if it fits your requirements.
  • Levitt, J. The Web Developer's Guide to Amazon E-Commerce Service. J9T Publications, 2005. Until recently, Amazon's Web services have been a work-in-progress, with significant changes made between releases. Thus, finding good examples and version-right information has been frustrating. Although written specifically for PHP developers, this book is still a fantastic reference for all developers looking for the fine details of using the Amazon Web services.
  • Musciano, C. and Kennedy, B. HTML and XHTML: The Definitive Guide, 5th edition. O'Reilly & Associates, 2002.
  • Raman, T. V. XForms: XML Powered Web Forms. Addison Wesley Professional. 2003.
  • Simpson, J. E. XPath and XPointer O'Reilly & Associates, 2002.
  • W3C XForms 1.0 (Second Edition) Specification: www.w3.org/TR/2005/PER-xforms-20051006
  • W3C XForms 1.1 Working Draft: www.w3.org/TR/xforms11. Among the features planned for the next XForms version are utility functions for XPath expressions such as the Luhn algorithm for credit card number validation, and better support for interacting with Web services.
  • W3C XML Events Recommendation: www.w3.org/TR/xml-events
  • W3C Document Object Model (DOM) Level 2 Events Specification: www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113


Page 2 of 2   « previous page

About Craig Caulfield
Craig Caulfield is a senior software engineer for a defense and commercial software house in Perth, Western Australia. He has a Bachelors degree in Computer Science, a Masters degree in Software Engineering, and holds certifications in Java, XML, DB2, UML, MySQL, and WebSphere.

  Subscribe to our RSS feeds now and receive the next article instantly!
In It? Reprint It! Contact advertising(at)sys-con.com to order your reprints!
ADS BY GOOGLE
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS