Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • IBM Mashup Center wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category IBM Mashup Center 3.0.0.1 Documentation Custom Search Scope...
Search
Learning Center > Find Out How > Passing parameters across Pages in Mashup Builder using cookies
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

IBM contributorRajesh Kartha
Contribution Summary:
  • Articles authored: 1
  • Articles edited: 0
  • Comments Posted: 0

Recent articles by this author

Passing parameters across Pages in Mashup Builder using cookies

It is a common usage scenario to persist parameter values across pages so that those could be subsequently used on other pages. A simple example is useridpassword, which the a user enters and this needs to be passed on to other pages to invoke other feedsurls that reside on them.

Learning Center articlePassing parameters across Pages in Mashup Builder using cookies

Added by IBM contributor Rajesh Kartha | Edited by IBM contributor Rajesh Kartha on October 20, 2011 | Version 17
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
It is a common usage scenario to persist parameter values across pages so that those could be subsequently used on other pages. A simple example is userid/password, which the a user enters and this needs to be passed on to other pages to invoke other feeds/urls that reside on them.
Tags: parameters, passing, cookie, pages
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:
alt text

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.
 
  

  • Edit
  • More Actions Show Menu▼


expanded Attachments (1)
collapsed Attachments (1)
Edit the article to add or modify attachments.
File TypeSizeFile NameCreated On
image/jpeg 39 KB JS_Adapter_wiring_from_UserInput.jpg 10/13/11 4:37 PM
expanded Versions (17)
collapsed Versions (17)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (17)Oct 20, 2011 3:37:09 PMRajesh Kartha  IBM contributor
16Oct 20, 2011 3:35:42 PMRajesh Kartha  IBM contributor
15Oct 14, 2011 12:35:27 AMRajesh Kartha  IBM contributor
14Oct 14, 2011 12:33:20 AMRajesh Kartha  IBM contributor
13Oct 14, 2011 12:30:24 AMRajesh Kartha  IBM contributor
12Oct 14, 2011 12:28:38 AMRajesh Kartha  IBM contributor
11Oct 14, 2011 12:28:03 AMRajesh Kartha  IBM contributor
10Oct 13, 2011 7:54:39 PMRajesh Kartha  IBM contributor
9Oct 13, 2011 7:41:38 PMRajesh Kartha  IBM contributor
8Oct 13, 2011 7:39:26 PMRajesh Kartha  IBM contributor
7Oct 13, 2011 7:38:44 PMRajesh Kartha  IBM contributor
6Oct 13, 2011 7:35:15 PMRajesh Kartha  IBM contributor
5Oct 13, 2011 7:32:28 PMRajesh Kartha  IBM contributor
4Oct 13, 2011 7:31:10 PMRajesh Kartha  IBM contributor
3Oct 13, 2011 7:30:12 PMRajesh Kartha  IBM contributor
2Oct 13, 2011 7:28:37 PMRajesh Kartha  IBM contributor
1Oct 13, 2011 4:37:31 PMRajesh Kartha  IBM contributor
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use