\r\n

51Degrees API Documentation  4.2Newer Version 4.4

Introduction

This example takes the very simple flow element described in the simple flow element example, and adds a JavaScript property to use client-side evidence.

Instead of using evidence which is already available, as the simple flow element example did, this example will send JavaScript to the a client to get the evidence.

Download Example

The source code used in this example is available here:

Dependencies

The flow element will need a dependency on the Pipeline core package

Select a tab to view language specific dependencies.

Data

The element data being added to the flow data by this flow element is a star sign. So this should have its own 'getter' in its element data. The additional property containing the JavaScript to get the date of birth is also added using the appropriate type.

Select a tab to view language specific element data implementation.

JavaScript

The client-side JavaScript for this example will be fairly simple. It will create a popup asking the user to enter their date of birth. It will then store the date of birth in a cookie named 'date-of-birth' and reload the page with the new cookie present.

The JavaScript to do this looks like:

// Ask the user for their data of birth.
var dob = window.prompt('Enter your date of birth.','dd/mm/yyyy');
if (dob != null) {
// Store it in a cookie.
document.cookie='date-of-birth='+dob;
// Reload the page with the new cookie.
location.reload();
}

Flow Element

Now the actual flow element needs to be implemented. For this, the flow element's base class can be used which deals with most of the logic. The element properties, evidence keys and the processing are all that need implementing.

Select a tab to view language specific flow element implementation.

Builder

Now the flow element needs one final thing, an element builder to construct it. This only needs to provide the flow element with a logger and an element data factory - as this example has no extra configuration options.

Select a tab to view language specific element builder implementation.

Usage

As this example gathers its evidence using client-side JavaScript, it will need to be run in a web environment. Using a web integration will mean that the flow element can be added, and the client-side JavaScript automatically run.

Select a tab to view language specific usage.