Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Motivation

This program demonstrates several different ways to call a web service from a sample XForms application. The example uses both HTTP POST and HTTP GET methods and shows how the results are returned into an instance in the model and how the page can be replaced with the results. The web service it calls is a simple web service that adds two numbers together.

Screen Image

XForms Adder Example After Execution

XForms Adder Example After Execution (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)

For the results to be put in the model using FireFox, make sure to add www.sa.kw.ua.sa and xforms-examples.google.com to your XForms white list using the Tools/Options/Security/Allowed Sites menu of FireFox. This is required since our web forms are hosted at one domain but the web services are hosted on another domain.

Load XForms Application

Sample Program

<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events" >
<head>
<title>XQuery Tester</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family: Arial,sans-serif;}

xf|input, xf|output {
display: table-row;
line-height: 2em;
}

xf|label {
display: table-cell;
text-align: right;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: small;
padding-right: 5px;
width: 150px;
}
</style>
<xf:model>
<xf:instance xmlns="" id="input-parameters">
<data>
<arg1>123</arg1>
<arg2>456</arg2>
</data>
</xf:instance>
<xf:instance xmlns="" id="submit-results">
<results>
<sum/>
</results>
</xf:instance>

<xf:submission id="get-instance" method="get" replace="instance" instance="submit-results"
action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder.xq"
separator="&">
<xf:toggle case="case-busy" ev:event="xforms-submit"/>
<xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
<xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
</xf:submission>

<xf:submission id="get-replace" method="get" replace="all" instance="submit-results"
action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder.xq"
separator="&">
<xf:toggle case="case-busy" ev:event="xforms-submit"/>
<xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
<xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
</xf:submission>

<xf:submission id="post-instance" method="post"
replace="instance" instance="submit-results"
action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder-post.xq">
<xf:toggle case="case-busy" ev:event="xforms-submit"/>
<xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
<xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
</xf:submission>

<xf:submission id="post-replace" method="post"
action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder-post.xq">
<xf:toggle case="case-busy" ev:event="xforms-submit"/>
<xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
<xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
</xf:submission>

<xf:submission id="get-test" method="get" replace="all"
separator="&"
action="http://xformstest.org/cgi-bin/showinstance.sh"/>

<xf:submission id="post-test" method="post" replace="all"
action="http://xformstest.org/cgi-bin/showinstance.sh"/>
</xf:model>
</head>
<body>
<h1>Using XForms to test XQuery</h1>
<p>Note, you must have xforms-examples.googlecode.com and www.cems.uwe.ac.uk in your whitelist for this demo to work.</p>

<xf:input ref="arg1" incremental="true">
<xf:label>Arg1:</xf:label>
</xf:input>
<xf:input ref="arg2" incremental="true">
<xf:label>Arg2:</xf:label>
</xf:input>

<xf:output ref="instance('submit-results')/sum">
<xf:label>Sum:</xf:label>
</xf:output>

<xf:submit submission="get-instance">
<xf:label>HTTP GET -> instance</xf:label>
</xf:submit>
<br/>

<xf:submit submission="post-instance">
<xf:label>HTTP POST -> instance</xf:label>
</xf:submit>
<br/>

<xf:submit submission="get-replace">
<xf:label>HTTP GET -> replace</xf:label>
</xf:submit>
<br/>

<xf:submit submission="post-replace">
<xf:label>HTTP POST -> replace</xf:label>
</xf:submit>
<br/>

<xf:submit submission="get-test">
<xf:label>HTTP Get Test</xf:label>
</xf:submit>
<br/>
<xf:submit submission="post-test">
<xf:label>HTTP Post Test</xf:label>
</xf:submit>
<br/>

<xf:switch>
<xf:case id="ready"/>
<xf:case id="case-busy">
<p>Waiting for results from server...</p>
</xf:case>
<xf:case id="case-submit-error">
<p>Submit error</p>
</xf:case>
<xf:case id="case-submit-done">
<p>Submit done</p>
</xf:case>
</xf:switch>
</body>
</html>

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
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
It will need additions if you want to align select, select1, textarea and other controls. A full CSS file for doing this is described later on in this cookbook. Note that you MUST put inputs inside of a group element for this stylesheet to work. Also note that the table can grow if the labels get to
CC BY-SA 4.0
This example has been tested using the FireFox browser. The use of the .xf-value class selector may not work on other systems.
CC BY-SA 4.0
This example uses a CSS style sheet to put the labels and fieldset legend in bold and align the login and password labels. By default the fieldset box stretches the entire width of the page. You can make it static by adding a style attribute with the width set to 250 pixels like this:
CC BY-SA 4.0
There are three message options: - **ephemeral** - a message that just appears briefly and goes away by itself - **modeless** - a message you can ignore for now - **modal** - a message the user must acknowledge before you go on ## Screen Image Here is a sceen image with the ephemeral message showing
CC BY-SA 4.0
lang="css"> textarea { font-family: sans-serif; height: 8em; width: 600px; } == Sample Program == lang="xml"> xmlns=" xmlns:xf=" XForms textarea xmlns=""> /> ref="Name" incremental="true"> Name: </xf:output ref="Name"> ref="MyTextValue"> Note: ## Discussion One of the challenges is to be able to for