UWA Frequently Asked Questions

These FAQs are designed to provide a better understanding of UWA technology, UWA app development guidelines and our others technical tools. They provide basic information, sometimes about fairly complex topics.

What makes a valid UWA app?

In order for your app to work properly within the UWA environment, it has to follow the following rules.

  • It MUST be well-formed XHTML
  • It MUST be UTF-8 encoded
  • It MUST feature the Netvibes namespace
  • It MUST place the JavaScript and CSS code in the HEAD section of the XHTML file
  • It SHOULD use JavaScript/Ajax to send/receive data
  • It SHOULD work within an IFRAME
  • It SHOULD make use of a legal or personnal Web service/API
  • It SHOULD be a static file - no server side scripting

Additionnaly, if you intend to test your app locally, it SHOULD make use of the following JavaScript and CSS emulation files:

<!-- Application Standalone emulation files -->
<link rel="stylesheet" type="text/css"
    href="//uwa.netvibes.com/lib/c/UWA/assets/css/standalone.css" />
<script src="//uwa.netvibes.com/lib/c/UWA/js/UWA_Standalone_Alone.js"></script>

I'm new to Javascript (no jQuery) can you give me some links.

Basics:

References:

Advanced:

Why can't I use the document.getElementById method?

The getElementById() method from the document object, while very useful for everyday uses, is not available in the widget object because there can be multiple instances of a given widget on a single page, and thus potentially multiple elements with the same id.

However, the widget object has the methods getElements() and getElement(), which can both be used to achieve the same result as getElementById() by using the element class - if they are applied to widget.body, which references the widget's root node.

widget.getElement('.myClass').addEvent('click', function (event) {

    // Stop event propagation
    UWA.Element.stop(event);

    // Your click event behavior here
});

var items = widget.getElement('.myItemClass');
items.forEach(function (item) {
    // Process item element behavior here
});

These two getElement*() methods are not the only ways:

If you dynamically generate your XHTML tags using JavaScript, you can directly obtain a reference for the element using the widget.createElement method - reference which can the be used to target said new element.

var myFriendsList = widget.createElement('ul', {
    'class': 'myFriendsList',
    html: {
        {
            'class': 'myFriend',
            tag: 'li',
            text: 'Bob'
        },
        {
            'class': 'myFriend',
            tag: 'li',
            text: 'John'
        },
    }
}).inject(widget.body);

I'm already using this fancy JavaScript Framework, can i keep using it?

The short anwser is yes, but you should not use a third party onDomReady event because UWA Apps are ready only when the "onLoad" event is triggered on the widget object.

Example of "onLoad" widget event usage:

widget.addEvent('onLoad', fonction() {
    // Launch you app here
});

Now, we strongly suggest that you only use UWA JS Runtime for making your UWA apps because rather than providing a black box like other JavaScript Framework the philosophy of UWA is to polyfill the existing enviroment to support JavaScript, CSS and DOM standard features.

Doing so will mean your UWA apps have better performance and make you write JavaScript instead of a fancy language with "$".

Here are some advantages that the UWA JS Runtime offers:

  • ECMAScript 5th Edition polyfills on String.prototype, Array.prototype, Object and Date object.
  • UWA.Widget object to store data, dispatch custom events and control the viewport of your app.
  • UWA.Data.request to make ajax requests even if the data source is not on the same domain as your app.
  • UWA.Storage to store your key/value database on the client side.
  • UWA.Element object to manipulate DOM Element using explict method names and with many polyfills (offsets, scrolls, events).
  • UWA.Element.setContent method to generate XHTML using JavaScript rather then putting HTML strings into your JAvaScript.
  • DOM Element style animations using <UWA.Fx>.
  • UWA.Class object to write "Object Oriented" JavaScript.
  • UWA.Json.path to filter big JSON objects, like XML with XPath, in order to avoid many loops.
  • Controls to display complex elements (UWA.Controls.Scroller, UWA.Controls.Map, {@link module:UWA/Controls/AudioPlayer.UWA.Controls.AudioPlayer|UWA.Controls.AudioPlayer})
  • And much more ;)

Note: We do not provide support for developers that use third party JavaScript Frameworks.

Why should I use UWA.Data.request rather than my own Ajax libraries?

UWA.Data.request provides a cross-domain Ajax solution that allow you to fetch data through Ajax calls even if your app is not on the same domain than your request.

That's why you should not use UWA.Ajax methods but UWA.Data.request method to perform such requests.

How to tell if my app is running in standalone mode?

Check for the value of the name property in widget.environment.

Here is a handy test:

var environmentName = widget.environment.name;
if (environmentName === 'uwa') {
    // Widget is running on standalone environment
} else if (environmentName === 'netvibes') {
    // Widget is running on netvibes environment
}

How i perform SOAP call

Here is an example of SOAP call using UWA.

var postBody = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"' +
'    xmlns:xsd="http://www.w3.org/1999/XMLSchema"' +
'    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" ' +
'    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" ' +
'    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
'    <SOAP-ENV:Body>' +
'        <mns:ProcessSRL xmlns:mns="http://www.SoapClient.com/xml/SQLDataSoap.xsd">' +
'            <SRLFile xsi:type="xsd:string">/xml/whois.sri</SRLFile>' +
'            <RequestName xsi:type="xsd:string">whois</RequestName>' +
'            <key xsi:type="string">microsoft.com</key>' +
'        </mns:ProcessSRL>' +
'    </SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>';

UWA.Data.request('http://www.SoapClient.com/xml/SQLDataSoap.WSDL', {
    type: 'xml',
    method: 'POST',
    postBody: postBody,
    headers: {
        "Content-Type": "text/xml; charset=utf-8",
        SOAPAction: "ProcessSRL"
    },
    onComplete: function (doc) {

        console.log('onComplete');

        // XML
        console.log(doc);

        // Or Json
        console.log(UWA.Json.xmlToJson(doc));
    },
    onFailure: function (error) {

        console.log('onFailure');
        console.log(error);
    }
});

How i perform SPARQL call

Here is an example of SPARQL call using UWA.

var dsn='http://dbpedia.org/sparql',
    query = 'SELECT ?film WHERE { ?film <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:French_films> }';

UWA.Data.request(dsn, {
    type: 'json',
    data: {
        "default-graph-uri": "http://dbpedia.org",
        query: query,
        format: "application/json",
        timeout: 0,
        debug: 'on',
    },
    onComplete: function (data) {

        console.log('onComplete');
        console.log(data);
    },
    onFailure: function (error) {

        console.log('onFailure');
        console.log(error);
    }
});

You can create other samples queries using http://dbpedia.org/snorql

I want use my own UWA Platform proxy instance in standalone mode?

If you have a UWA Platform instance that has access to your internal data and want, during the development phase using standalone mode, access to your data you have to configure UWA before including the standalone emulation files.

Example:

<!-- Application Standalone emulation config -->
<script type="text/javascript">
//<![CDATA[

    // Overide UWA hosts values for development purpose.
    // This script will be ignored once the app is
    // compiled because it's overide UWA namespace.
    var UWA = {
        hosts: {
            exposition: 'http://uwa.example.org'
        }
    };

//]]>
</script>

<!-- Application Standalone emulation files -->
<link rel="stylesheet" type="text/css"
    href="//uwa.netvibes.com/lib/c/UWA/assets/css/standalone.css" />
<script type="text/javascript"
    src="//uwa.netvibes.com/lib/c/UWA/js/UWA_Standalone_Alone.js"></script>

By setting the "exposition" property of UWA.hosts you ask UWA to use your UWA instance for cross-domain Ajax requests.

Notice that this script tag will be ignored once the app is compiled on another platform because it overides the UWA namespace.

Requirements:

  • The UWA.hosts overide should be in a separate script tag
  • The script tag should be inserted before the standalone emulation files

How do I tell if my app is running in an environment that supports "touch" events?

Check for the value of the touch property in UWA.Utils.Client.Features.

Here is a code sample that handles touch and click:

var isTouch = UWA.Utils.Client.Features.touch,
    eventHandler = function (event) {
        // Handle your event here using event.type value
        widget.body.setContent('Event:' + event.type);
    },
    eventsHandlers = {},
    eventNames = {
        start: isTouch ? 'touchstart' : 'mousedown',
        move: isTouch ? 'touchmove' : 'mousemove',
        stop: isTouch ? 'touchend' : 'mouseup',
        cancel: isTouch ? 'touchcancel' : 'mouseup'
    };

// Map Events
eventsHandlers[eventNames.start] = eventHandler;
eventsHandlers[eventNames.move] = eventHandler;
eventsHandlers[eventNames.stop] = eventHandler;
eventsHandlers[eventNames.cancel] = eventHandler;

// Add Events
widget.body.addEvents(eventsHandlers);

How do I avoid caching while developing my UWA app?

When your UWA app is compiled in order to be displayed on Netvibes or other platforms, your app source is cached for performance reasons.

In order to debug your app in those enviroments you have to set the following meta in the head of your app source.

<meta name="debugMode" content="true" />

Shouldn't there be something at "http://www.netvibes.com/ns/"?

UWA apps use a new xhtml namespace, defined with the name widget. That namespace uses the URI http://www.netvibes.com/ns/. At the time of writing, this URI returns a 404 HTTP error: no document resides there.

As said in the XML Namespace specification:

The namespace name, to serve its intended purpose,
SHOULD have the characteristics of uniqueness and persistence.
It is not a goal that it be directly usable for retrieval of a schema (if any exists).
(source: http://www.w3.org/TR/REC-xml-names/)

While we might put a specific page at the namespace URI sometimes in the future, that URI is already usable as it is: its intent is to give a unique and persistent URI, which it does already.

Can i use externals Javascript and CSS files?

To use external libraries inside your UWA app you just have to inject the script or link tags after the Standalone emulation files.

<!-- Application Standalone emulation files -->
<link rel="stylesheet" type="text/css" href="//uwa.netvibes.com/lib/c/UWA/assets/css/standalone.css" />
<script type="text/javascript" src="//uwa.netvibes.com/lib/c/UWA/js/UWA_Standalone_Alone.js"></script>

<!-- Application External files -->
<link rel="stylesheet" type="text/css" href="http://example.com/MyCompany/MyStyle.css" />
<script type="text/javascript" src="http://example.com/MyCompany/MyLib.js"></script>

UWA Implementations will resolve the relative paths using the current url of the UWA app.