Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Background and Motivation

Since K&R wrote the first book on C programming, it has become tradition for programming books to begin with a "Hello World" program. Running this program will indicate if you have XForms installed correctly.

Here is a sample "hello world" program in XForms. It uses one input, one variable in the model, and one output. You should be able to just copy and paste the text into a program such as Notepad and save it to a file such as hello.htm. This will tell you if you have the Firefox or other browser extension installed correctly.

Screen Image

(Note that this is only a .jpg and NOT an actual form!)

Hello World

Hosted hello world example

Program

To run this program, just copy the following text into a file "hello.xhtml" and open it with your web browser with the appropriate XForms extension loaded.

xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">

Hello World in XForms

xmlns="">

Type your first name in the input box.

If you are running XForms, the output should be displayed in the output area.

ref="PersonGivenName" incremental="true">
Please enter your first name:

/>
value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')">
Output:

Problems

If this program does not work, you may not have the extension or plug-in installed in your browser.

For help see Installing XForms in FireFox.

Note that if you have the NoScript Firefox extension installed, you may need to configure NoScript to allow scripts from the location from which you are loading HelloWorld.

Also note, in Firefox the file has to be saved with a xhtml or xml extension. A file with a .html exension won't show the XForms.

Discussion

Note that the file looks much like a standard HTML file with a few exceptions.

  • there is a namespace declaration at the beginning of the file and there are two elements with a xf: prefix in front of them.
  • there is something called a model inside the HTML **** element
  • There are some new elements: input and output.

The two important lines are:

ref="PersonGivenName" incremental="true"/>

and

value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')"/>

As the user types, this line takes the input that the user types in and copies it to the instance variable "PersonGivenName". Each time you type a character this program updates the output and using the XPath concat() function to wrap the string "Hello " in front of the name and the string ". We hope you like XForms!" after it.

You should also note that there is not a single line of JavaScript required to run this program. Getting rid of JavaScript is one of the biggest reasons people are migrating their applications to XForms.

Experiment

Try changing the input attribute incremental from:

incremental="true"

to:

incremental="false"

The output should update only after you enter "Tab" or press the "Enter" (Return) key.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
ref="inp1"> Ephemeral message: level="ephemeral" ev:event="DOMFocusIn">This is an ephemeral message. Don't worry, I go away after a few seconds. Press enter in the input field to get a modeless message: ref="inp2"> Modeless message input: level="modeless" model="myModel" ref="/data/MyMessage" ev:eve
CC BY-SA 4.0
Most people that have studied [MVC]( architecture agree on two aspects: The Model and the View. The model is where you store your data or your business objects. The View is what the user sees. But many variations of MVC have very different implementations of a controller.
CC BY-SA 4.0
The model has instance data in it to store the values that the user enters in the form. The view is part of the presentation in the body of the HTML document. ## Sample Program xmlns=" xmlns:xf=" XForms inputs with labels xmlns=""> Enter your first name, and last name. ref="PersonGivenName" incremen
CC BY-SA 4.0
The name of the Data Element is a concatenation of three fields: the Object Class Name, the Property Name and the Representation Term. The first two are text fields and the third is a value that is picked from a list. This form creates a single output based on the values of the input fields. This sh
CC BY-SA 4.0
Here is an example program that demonstrates this. ## Screen Image Here is a screen capture of the application: Note that top grid is actually just unlabeled input cells. Below that is a sample output inside a table. You should be able to change any of the input cells, enter a tab, and see the outpu
CC BY-SA 4.0
This example has two input fields for a person's first and last name and two output controls. ## Sample Program xmlns=" xmlns:xf=" xmlns:xs=" xmlns:xsi=" Your Title Here xmlns=""> id="PersonGivenName" nodeset="/data/PersonGivenName"/> id="PersonSurName" nodeset="/data/PersonSurName"/> bind="PersonGi