XForms 1.1 Chinese Translation - Chapter 2 Introduction to XForms

sponsored links
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.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of XForms 1.1 Chinese Translation - Chapter 2 Introduction to XForms

  • Hibernate query: HQL and Criteria

    HQL query methods generally used in more general way through the query query. Examples are as follows: The Criteria is a more than HQL query object-oriented approach: Created as follows: Criteria crit = session.createCriteria (Object.class); crit.add ...

  • Hibernate configuration parameter table

    # # Auto schema export # hibernate.hbm2ddl.auto create-drop # hibernate.hbm2ddl.auto create # hibernate.hbm2ddl.auto update # hibernate.hbm2ddl.auto validate The first is to create a table in the delete the original data, we can insert data, delete p ...

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • Memo hibernate problem

    hibernate using myeclipse automatically generated HBM mapping file will be schema ="***" catalog ="***" Separately are the database instance name and database name, but in fact has been stated jdbc url connection database, are the ...

  • Java technology 25 study points

    1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic

  • Hibernate pessimistic locking mechanism for locking and optimistic locking

    hibernate lock mechanism 1. Pessimistic lock It refers to the modification of data by outsiders hold a conservative attitude. The assumption that at any time access to data, may also have another client to access the same data, in order to maintain t ...

  • Spring + Hibernate to use Glassfish Database Connection Pool

    applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " http://www.springframework.org/schema/beans " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " ...

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • Java Technology wishing cow needed 25 points of study

    1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries