The article describes how the need for passing of parameters across pages can be achieved using cookies.
Consider a page with a UserInput widget that asks the user to enter information, example: Username/Password, which
in turn needs to be passed to other pages. The simplest way to persist this information across pages is to use cookies which
can be done very easily in a few lines of javascript. The out-of-box JavaScript (JS) Adapter widget can be used to add custom javascript on any page.
Add a Javascript to the page and wire it from the User Input widget using the 'Data Object as JSON' option as shown below:
Click on Edit Settings of the JS Adapter widget and add the necessary code to read the JSON received, parse it and save it as cookies for a
set duration. Here is a snippet that saves the username and password parameter values as 'ws_username' and 'ws_password' named cookies respectively with an
expiration of 1 day:
if(payload != null){
var today = new Date();
var expire = new Date(); var nDays=1;
var myJSON= eval('(' + payload + ')');
var ws_username= myJSON["username"];
var ws_password= myJSON["password"];
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = "ws_username="+escape(ws_username)+ ";
expires="+expire.toGMTString();
document.cookie = "ws_password="+escape(ws_password) + ";
expires="+expire.toGMTString();return payload;
}
else{
return payload;
}
Now that the cookies are set, we can move on to the next page where these cookies need to be read and used accordingly.
Create another page in the Mashup Builder and add a JS Adapter widget to the page. Click on the Edit Settings of the widget and add the code
to read the cookies stored previously. Here is a snippet that does the job:
function readCookie(cookieName) {
var theCookie=" "+document.cookie;
var ind=theCookie.indexOf(" "+cookieName+"=");
if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"=");
if (ind==-1 || cookieName=="")
return "";
var ind1=theCookie.indexOf(";",ind+1);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+2,ind1));
}
if(payload==null){
var user=readCookie("ws_username");
var pwd=readCookie("ws_password");
payload="username="+user+"&password="+pwd;
this.iContext.iEvents.publishEvent ("Provide Edited Data", payload);
}
return payload;
Note the last line:
this.iContext.iEvents.publishEvent ("Provide Edited Data", payload);
This is really important. It performs the manual event firing and enables other widgets, wired to this JS Adapter widget, to receive the 'payload' from the JS Adapter widget and in turn perform their respective function.
Here is a page created on GreenHouse:
https://greenhouse.lotus.com/mum/mashups?nst=pid=09200718D1C72AA37449D842B3748D00009F&
If stored information in cookies is a security concern, you could add some extra javascript code to remove the cookies when the user is done with the current session.