The user interface controls described so far can collect user data and enable the triggering of actions in response to user interaction events and are sufficient to implement a large number of online interaction. When designing XForms, we felt that enabling the user to trigger the specific action of submitting the collected data to the Web server was sufficiently important to deserve its own user interface control. HTML4 had achieved such submit buttons by overloading the input control with a value of submit for attribute type . We decided to define element User interface control This section describes control 3.8.1 Anatomy of Control |
Binding | Optional XForms binding attributes, that is, attribute pair ( model , ref ) or attribute bind , is used to specify the data that is to be submitted. These binding attributes are used to address a specific portion of the instance if only a part of the data collected is to be submitted. By default, the first data instance is submitted in its entirety. |
action | Attribute action specifies the protocol and location for data submission. The name was chosen to retain consistency with HTML forms that use an action attribute on element |
method | Specifies the method used to submit the data. The value of this attribute may be one of a predefined set of values designed to cover commonly used methods on the Web today. It is also designed to be extensible to allow future methods . The predefined values include | ||||||||||||||
| |||||||||||||||
Method names not appearing in this list may be used as long as they are qualified with the appropriate namespace. This provides an extensibility mechanism for easily incorporating emerging XML protocols. | |||||||||||||||
separator | Optional attribute separator (default is ; ) specifies the separator character used when encoding multiple fields in conjunction with method get . This is present to enable authors to choose explicitly between using & and ; to separate encoded fields within a URL when using method get . The older HTML choice of & is not XML-friendly, and as a result Web forms are now beginning to use ; as the separator. This attribute is present to give the author explicit control if necessary. | ||||||||||||||
encoding | Attribute encoding specifies the encoding to use when serializing the data. | ||||||||||||||
replace | Attribute replace enables XForms-aware user agents and servers to process intelligently partial submission and data refresh. When using today's HTML forms, submitting data to a server results in the response being delivered as a new HTML page. As a consequence, transactions consisting of multiple stages require retransmission of the entire Web page from server to client at each stage of the transaction. | ||||||||||||||
This was necessitated by the lack of separation between model and user interaction inherent in the HTML forms design. Given its model vs. interaction separation, XForms provides more design flexibility with respect to how the response to a form submission is processed on the client. Since we have separated the model from the user interface, the XForms author can specify whether a submission response is to update one of either the XForms model, the user interface, or both via submission attribute replace . XForms 1.0 specifies three predefined values for attribute replace : | |||||||||||||||
| |||||||||||||||
In addition to the values shown here, namespace qualified values may be used for attribute replace when experimenting with new interaction behaviors. The default behavior is to replace both the model and user interface to match the behavior of today's HTML forms. Replacing the instance provides a powerful means of refreshing the user interface without retransmitting all of the original markup. Note that an XForms model can contain more than one instance; this is an advanced concept that is introduced in a later chapter. When using multiple instances in a model, XForms always defaults to the first instance, and this is true in the case of attribute replace as well. |
The metadata encapsulated by element submission
about how to serialize instance data was modeled after XSLT element
output
. XForms allows the following attributes taken from XSLT element
output
on element
submission
. These are listed separately since they are used less often than the
submission
attributes described earlier:
indent | Boolean that specifies if the instance data should be indented when it is serialized as XML |
version | Specifies the version of XForms in use |
omit-xml-declaration | Specifies if the serialized instance data should include the following XML Processing Instruction: <?xml version="1.0"?> |
standalone | Specifies if the serialized instance data is a stand-alone XML document |
cdata-section-elements | Names elements in the instance whose contents should be escaped as XML CDATA sections when serializing as XML |
Next, we create element submission
(see Figure 3.28 for the markup) needed to complete the shopping cart example. Submitting the purchase order by activating control
submit
causes the data stored in /e-store/cart to be serialized and transmitted to the location specified by attribute action .
< model xmlns ="http://www.w3.org/2002/xforms">... < submission id ="buy" ref ="/e-store/cart" action ="http://example.com/e-store" method ="post" replace ="instance"> < action > < message > Ordering...</ message > </ action ></ submission > </ model >
The server responds with an XML instance that holds updated information about the user's currently open orders in subtree /e-store/open-orders . When this response is received by the XForms client, the data model is updated, and any user interface controls that bind to updated portions of the data model are refreshed. Thus, activating the buy submit control results in the user interface being updated with information about the newly opened order.
Assume that the items bought by the user have been collected into the XML subtree rooted at cart
. Notice that in this example not all the nodes in the XForms model instance are to be submitted to the server. This situation often arises when an XForms application uses a portion of the data model to store intermediate computed values. Such partial submission is also useful if the XForms author has chosen to use a single model/instance pair to store all of the data for an application. For instance, the example shown in Figure 3.29 contains four XML subtrees under the
e-store
root element:
< model xmlns ="http://www.w3.org/2002/xforms"> < instance > < e-store xmlns =""> < specials >...</ specials > < scratch >...</ scratch > < cart > < item >< sku />< quantity />< price /></ item > ...</ cart > < open-orders >< order />...</ open-orders > </ e-store ></ instance > </ model >
| Subtree rooted at |
| Subtree rooted at element |
| Subtree rooted at element |
| Subtree that holds information about the user's open orders. This subtree will be used by the XForms server hosting the e-store application to hold information about the user's currently open orders. |
In this case, we use an appropriate binding attribute
ref="/e-store/cart"
on element submission
to locate the data that is submitted to the server.
Attribute action specifies where the data is to be submitted. Attribute method specifies the method to use for serializing and transmitting the data. Attribute replace is used to specify how the server response is to be interpreted. In this application, the author has specified that the server response be treated as an update to the XForms data model.
Finally, the author has set up an event handler inside element submission
(by using action
message
) that displays a message to the user that the purchase order is being submitted. Event handlers inside element
submission
are invoked before the data is transmitted to the specified location. This gives authors the ability to add custom interaction behavior when data is being submitted. Note that today's HTML authors depend on scripting for achieving similar functionality by attaching an event handler to the onsubmit event.
We conclude this section with a round-up that summarizes submit processing from the time the user activates control submit
to the final step of updating the user interface based on the server response. We describe this process using events and the actions they invoke. The XForms processing model is defined declaratively in the XForms specification to ensure that implementations achieve the same results irrespective of variations in the underlying implementation. Following are the steps that occur in sequence during submit processing in the example covered in this section:
Trigger | User triggers control |
Target | Event xforms-submit is dispatched to the |
Handler | Upon receiving this event, element |
Locate | Next, the binding attribute specified on element |
Serialize | The located portion of the instance data is serialized in accordance with the values specified for attributes method , mediatype , and encoding . |
Transmit | The resulting serialization is transmitted to the location specified via attribute action using the method specified by attribute method . |
Response | The server response is processed as specified by attribute replace . The value of instance for this attribute causes the XForms client to treat the response as an update to the data model. |
Refresh | Once the data model has been updated as specified by the server response, the user interface is refreshed. Here, the server response has updated sub tree /e-store/open-orders . User interface controls that binds to /e-store/open-orders are refreshed to display the newly available information. |
Control | Description |
---|---|
| Generic input control |
| Password entry |
| Multiline text entry |
| Select from a set |
| Exclusive select from set |
| Pick from range of values |
| Upload data |
| Activate command |
| Trigger submission |