XForms 1.1 Chinese Translation - Chapter 2 Introduction to XForms

2 XForms Introduction

XForms is the many years of experience in HTML form based on the design. HTML Forms have formed the backbone of e-commerce revolution, showing their value, also shows a number of worthwhile improvement.

Contrast XForms with HTML Forms, apart from XForms is XML format, its main difference is the separation of the data collected and the collection of these values of the control tags (markup). By doing this, not only makes XForms easier management (where at a glance what data is submitted), but also easier to re-form, because the underlying basis for the form part (data part) is no longer with the use of mandatory binding of its pages.

The second important difference is that while XForms is designed to integrate with XHTML, but no longer limited and the only part of the language XHTML, but can be integrated into other suitable markup language.

XForms efforts to improve the form to create, reuse, internationalization, accessibility, availability, and device-independent nature. The following main advantages of the use of XForms is summarized:

Strong data types

The data submitted is strong data types, you can use existing tools to be checked. This reduces the right and from the server identified between the needs of accelerated form filling.

XML submission

This eliminates the customized server-side logic to integrate the data submitted to the background applications. The received XML instance document can be applied directly to verify the background and processing.

Reusing existing models (schema)

This eliminates duplication and will ensure that the underlying business logic to change the result of verification (validation) rules update, do not need to re-create the XForms application validation constraint

Increase in external rules

This makes XForms form designer can provide the background beyond the basic set of constraints. To provide additional constraint as part of the XForms model generated enhanced the overall availability of Web applications.

Internationalization

Examples of the use of data XML1.0 so as to ensure the submitted data is internationalization.

Enhanced ease of use

XForms separation of content and performance. User interface controls packaged all the relevant meta-data (such as labels), thus enhancing the use of different forms (modalities) when the application ease of use. XForms user interface controls are generic and device-independent.

Multi-device support

The high-level user interface controls the nature and the resulting user interface based on the purpose of creating a way that user interaction can be applied to different devices.

Less use of script

A statement by defining the event-based XML processor (event handlers) (covering the general use cases), the majority of the majority of XForms documents can be static analysis, reducing the event handler for the necessary needs of the script.

2.1 Example

In the XForms approach, the form consists of two parts: one describes the form what to do, called XForms Model, the other part describes how to display the form.

A simple e-form may appear as follows:

XForms 1.1 Chinese Translation - Chapter 2 Introduction to XForms

Obviously, we want to collect cash or credit cards on behalf of a value, and if using a credit card, card number and expiration date values.

This can be expressed in the XForms model element, which is usually included in the XHTML part of the head.

<xforms:model>

<xforms:instance>

<ecommerce xmlns="">

<method/>

<number/>

<expiry/>

</ ecommerce>

</ xforms: instance>

<xforms:submission action="http://example.com/submit" method="post""submit" includenamespaceprefixes=""/>

</ xforms: model>

This only shows that we have to collect the three parts of information (note that we do not talk about their type), and use the action attribute of the URL to submit the information.

XForms defines a device-independent, platform-independent set of form controls, this collection for general purposes. These controls through the XForms binding mechanism to bind to the XForms Model. In this simple example is to use the control ref attribute. In XHTML, this tag often appears in body parts (note that we deliberately left out in the XForms namespace prefix):

<select1 ref="method">

<label> Select Payment Method: </ label>

<item>

<label> Cash </ label>

<value> cash </ value>

</ item>

<item>

<label> Credit </ label>

<value> cc </ value>

</ item>

</ select1>

<input ref="number">

<label> Credit Card Number: </ label>

</ input>

<input ref="expiry">

<label> Expiration Date: </ label>

</ input>

<submit submission="submit">

<label> Submit </ label>

</ submit>

Note that this design of the following characteristics:

  • l there is no hard-coded user interface requires the use of radio button. Different devices (such as voice browsers) can display the appropriate "radio" concept.
  • l-core form controls always contains the label associated directly with them as a child element - the key feature used to enhance ease of use.
  • l there is a form element is not necessary to include these tags, this is not the same as HTML. (See more than 2.4 form a document in a document on how to create multiple forms of the details)
  • l said that the markup form controls should be simple in comparison with the HTML form.

You can bind form controls to the model the ability to make the integration of XForms into other host languages (host language) simplified, because you can use any form controls bound to the model tag.

2.2 The provision of XML instance data

XForms Processor can directly submit XML formatted data, in this case, the submitted data is as follows:

<ecommerce>

<method> cc </ method>

<number> 1235467789012345 </ number>

<expiry> 2001-08 </ expiry>

</ ecommerce>

XForms processor through this instance data to track the status of partially completed form. As an example shown in the initial value of instance data can be provided or is empty. Element instance essentially saved when the user fill out the form to update the XML document. This allows the designer complete control of the form submitted by the XML data structure, including the name of spatial information. When the form is submitted, the instance data are serialized into XML documents. Here is another version of the previous example:

Model

<xforms:model>

<xforms:instance>

<payment method="cc" xmlns="http://commerce.example.com/payment">

<number/>

<expiry/>

</ payment>

</ xforms: instance>

<xforms:submission action="http://example.com/submit" method="post" includenamespaceprefixes="#default"/>

</ xforms: model>

In this case, the submitted data is as follows:

Submitted Data

<payment method="cc" xmlns="http://commerce.example.com/payment">

<number> 1235467789012345 </ number>

<expiry> 2001-08 </ expiry>

</ payment>

This design has the following features:

  • l XML instance data structure is very flexible, including the use of property. Note that using the XML name space, the form designer choice of packaging elements (whether it refers to payment) contains the instance data.
  • l In the XML structure, number and expiry empty element to act as placeholders will be filled with user-supplied form data.
  • l by example data provide the initial values of form controls ( "cc"), in this case is the method attribute. In the submission of the XML, if the user changes the display data in form controls, the initial value will be replaced by user input.

In order to connect an instance of the data and form controls, form controls need to change the ref attribute to point to the correct part of the instance data, use the following binding expression (binding expression):

Binding Form Controls to Instance Nodes with ref

... Xmlns: my = "http://commerce.example.com/payment"

...

<xforms:select1 ref="@method"> ... </ xforms: select1>

...

<xforms:input ref="my:number"> ... </ xforms: input>

...

<xforms:input ref="/my:payment/my:expiry"> ... </ xforms: input>

Binding expressions are based on Xpath [XPath1.0], including the use of @ symbol to point to properties, as shown above. Note that, in order to demonstrate the purpose of the first two expressions using the XPath context node, this node, the default is the highest level element (this is my: payment). The third expression shows an absolute path.

2.3 Value Constraints

XForms allows filling in the form when you check the validity of data. In the absence of explicitly specify the type of data collected information on the case, all the values are in the form of a string to return, but you can set the value in the instance of the type of data. In this example, number should only accept the 14-18 a number between, expiry accept only a valid month / date combinations.

In addition, number and the expiry of the credit card information form controls only in the method in the "cc" option is selected when the relevant (relevant), and in this case is necessary.

By specifying an additional component of XForms - Model entry characteristics (model item properties), can be expressed in the form designer contains a wealth of information on the effectiveness of verification. This information is available from XML Schemas, or other proprietary XForms additional (specific additions), as relevant gain. These features (should refer to relevant) appear in the bind elements, while Schema constraints (whether it refers to type) expressed in the XML Schema section, can be internal or external, such as:

Declarative Validation with Model Item Properties

... Xmlns: my = "http://commerce.example.com/payment" ...

<xforms:model>

...

<xforms: bind nodeset = "/ my: payment / my: number"

relevant = "/ my: payment / @ method = 'cc'"

required = "true ()"

type = "my: ccnumber" />

<xforms: bind nodeset = "/ my: payment / my: expiry"

relevant = "/ my: payment / @ method = 'cc'"

required = "true ()"

type = "xsd: gYearMonth" />

<xs:schema ->

...

<xs:simpleType name="ccnumber">

<xs:restriction base="xsd:string">

<xs:pattern value="\d{14,18}"/>

</ xs: restriction>

</ xs: simpleType>

...

</ xs: schema>

</ xforms: model>

Note:

In the above example, because the calculation of expression (computed expression) of the evaluation context node is through the binding expression (see 7.2 evaluation context) decided, therefore, relevant expression uses absolute path XPath notation (in / start) Therefore, in the above first bind relevant in the relative node path should be relative to the /my:payment/my:number The .

2.4 The document contains a number of forms

XForms processing on a single document can contain no limit on the number of independent form. When a single document that contains multiple forms, each form needs a separate model element, and has an id attribute, as you can include it in the document refer to it elsewhere.

In addition, form controls should specify which model element contains the instance data to bind them. This is by acting as part of the binding properties model properties to achieve. If there is no binding element for the specified model attribute, then using the last ancestor binding element of the model attributes, if not, then use the document in the first XForms Model. This technology is called 'the scope of analysis' (scoped resolution), in the XForms frequently use.

The following example adds a form of e-commerce poll.

Adding a poll model

<xforms:model>

<xforms:instance>

... Payment instance data ...

</ xforms: instance>

<xforms:submission action="http://example.com/submit" method="post"/>

</ xforms: model>

<xforms:model"poll">

<xforms:instance>

<helpful/>

</ xforms: instance>

<xforms:submission"pollsubmit" -/>

</ xforms: model>

In addition, the following markup will appear in the document body parts:

Form Controls for poll model

<xforms:select1 ref="/helpful" model="poll">

<xforms:label> How useful is this page to you? </ xforms: label>

<xforms:item>

<xforms:label> Not at all helpful </ xforms: label>

<xforms:value> 0 </ xforms: value>

</ xforms: item>

<xforms:item>

<xforms:label> Barely helpful </ xforms: label>

<xforms:value> 1 </ xforms: value>

</ xforms: item>

<xforms:item>

<xforms:label> Somewhat helpful </ xforms: label>

<xforms:value> 2 </ xforms: value>

</ xforms: item>

<xforms:item>

<xforms:label> Very helpful </ xforms: label>

<xforms:value> 3 </ xforms: value>

</ xforms: item>

</ xforms: select1>

<xforms:submit submission="pollsubmit">

<xforms:label> Submit </ xforms: label>

</ xforms: submit>

The main difference here is the use of model = "poll" to specify an instance. Note, submit through the ID point to the submission element, does not require binding attributes.

More Xforms the examples in Appendix H to find a complete XForms examples.

分类:Java 时间:2009-07-11 人气:290
分享到:
blog comments powered by Disqus

相关文章

  • Maximum value of SQL Server 2005 data types 2010-07-21

    I want to store the many documents are more than 8000 bytes, then it is obviously not for the VARCHAR data type of work. As an alternative, TEXT data type is used to define the storage of data fields. Because each can accommodate 2GB of content TEXT,

  • ThreadLocal Application: In order to add transaction processing business logic layer 2010-03-29

    http://hi.baidu.com/luodaijun/blog/item/2ee9cbbf4c960e0a19d81fad.html Take a look at how to use the public void add(EmployeeModel emp) { try { this.benginTransaction(); // Begin transaction dao.add(emp); // Other business logic this.commit(); // Comm

  • Struts form validation and business logic verification 2010-03-29

    A Forms Authentication in general to determine whether it is empty, the realization of the same validation JavaScript function (the purpose is to prevent when JS is disabled can not be the desired results) public ActionErrors validate(ActionMapping m

  • Log in business logic 2010-04-20

    Log in business logic: 1. At the interface, in addition to add the user name and password input box and submit the Cancel button, we can add validation code, and whether Facebook; 2. After we click the submit button, to conduct 11 of the verification

  • XForms 1.1 Chinese Translation - Chapter 1 on the XForms standard 2009-09-02

    1 on the XForms standard 1.1 Background Web forms are an important component of interactive Web applications has been the main implementation. Web applications and e-commerce solutions for Web forms made new demands, that is, a better experience with

  • SQL Server data types are easily confused 2010-07-21

    SQL Server data types are easily confused MSSQL database Clicks: 434 (1) char, varchar, text, and nchar, nvarchar, ntext the length of char and varchar are between 1 to 8000, their difference is that char is a fixed length character data, and varchar

  • sql server data types char and nchar, varchar and nvarchar, text and ntext (Reprinted) 2010-09-09

    the difference between varchar and nvarchar: varchar (n) Length of n bytes of variable length and non-Unicode character data. n must be a range of values between 1 and 8,000. Storage size of the input data byte actual length, not n bytes (such as var

  • Google File System (Chinese translation) 2010-11-27

    Google File System GFS is a scalable distributed file system for large, distributed, access to large amounts of data applications. It runs on inexpensive commodity hardware, but can provide fault tolerance. It can provide the overall performance of a

  • OAuth 2.0 Chinese translation (a) 2011-04-07

    OAuth 2.0 is likely to be the next generation of "user authentication and authorization" standard, currently in the country yet very tricky technical information. In order to promote the "openness" for the industry are more likely to u

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.416 (s). 12 q(s)