Use Dojo to develop custom business space Widgets, part 4th

Source: Internet
Author: User
Tags json

The custom widgets we developed for this series are based on the Dojo version that is included with the WebSphere V7.0 supported Business Space (hereinafter referred to as Business space), which has been tested in Mozilla Firefox 3.0.11. It's just that the common framework concept we develop can even be applied to applications that use Dojo, but not to Business space. Learning this series requires a basic knowledge of the DOJO and iWidget frameworks.

We will discuss topics that are frequently encountered in Dojo based applications. This series is divided into the following sections:

Part 1th: Generate DOJO markup using a generic markup handler

Part 2nd: Create a Dojo DataGrid component with paging functionality with a common grid handler

Part 3rd: Using multiple templates in IWidget and inheriting from basic widgets

Part 4: Using a universal rest handler to emit configurable rest calls from IWidget

In the 4th part, you will learn how to use a general-purpose rest handler to invoke a rest service from IWidget, which is based on the following principles:

The rest URI is usually dynamic, and part of the URI (URL parameter) is dynamically replaced by IWidget before the rest service is invoked. Our design reads the rest URI from the JSON file according to the corresponding rest keyword.

The query parameters are dynamically substituted.

The REST handler currently supports JSON, but is easily enhanced as needed to support XML and other types.

The REST handler supports get, Post/rawpost, put, Rawput, and DELETE operations, as well as file uploads and downloads.

In this article, we'll describe the implementation of the REST handler and how to use it in your iWidget.

The following files are available for download in Part4samplecode.zip:

Jsonresthandler.js: Universal REST Handler Javascript class.

Resturi.json: A JSON file that contains a REST URI.

TestJSONRestHandler.js:Javascript class that shows how to use Jsonresthandler in your code.

Implementation of the Handler

The Jsonresthandler Javascript class loads the JSON file containing the REST URI information in the Loadrestconfig () method.

The Loadrestconfig () method accepts the following parameters:

Type: The type of operation, such as Get/post/put, and so on.

The KeyName in the Restcallkey:json file, such as EmployeeList.

Restendpoint: The rest endpoint of a rest application, such as Http://<server>:<ip>/restAPI.

Loadmethod: This method is invoked when the REST URI is successfully loaded.

Errormethod: This method is invoked if there is an error calling the REST URI.

The syncflag:rest call should be synchronous or asynchronous (true or false).

Thisvar: Invokes a reference to the class.

Parameters: Contains 3 variables (urlparameters, queryparameters, content). If the URI has a URL or query parameter, the object needs to be set with the appropriate value.

The content is sent only when the POST is requested.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.