Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Ext Session

Ext Session

Ratings: (0)|Views: 10|Likes:
Published by Arijit Samanta

More info:

Published by: Arijit Samanta on Jun 25, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

07/25/2014

pdf

text

original

 
Here is the scenario: You want need to have some kind of session mechanism,that will allow you to store data across different views in you Ajax application.Let's say you go from form A to form B and there is some data that form Bneeds from form A, but form A is no longer in the DOM, so you cannot grab itfrom there. EXTJS has a build session manager, that in the core has two"providers" (storage mechanisms) one just stores the data in JavaScriptvariable, which in case of reloading the page will get lost, and the other storesthe data in a cookie. One of these two "providers" seem to be robust enough(cookies have character limit, and don't seem to be a good storage mechanismfor larger data). I decided to take the default Ext.state.Manager provider, andadd a "backup" method, that sends the data to the serve, when somebody hitsF5, and puts the data back to the JavaScript variable, when the page loadsagain. (save on unload, retrieve on load)So enough of theory, here is the is the code:(function() {//namespace creation and create local shortcutvar m = Ext.namespace("MyLib.Session"); var settings = {sessionUrl: "/Ajax/GetSession",sessionPostUrl: "/Ajax/SetSession"};var session = {}; //converts object to stringvar objectToString = function(o){ 
 
var parse = function(_o){ var a = [], t; for(var p in _o){ if(_o.hasOwnProperty(p)){ t = _o[p]; if(t && typeof t == "object"){ a[a.length]= p + ":{ " + arguments.callee(t).join(", ") + "}"; }else { if(typeof t == "string"){ a[a.length] = [ p+ ": \"" + t.toString() + "\"" ];}else{a[a.length] = [ p+ ": " + t.toString()];} }
 
}} return a; } return "{" + parse(o).join(", ") + "}"; }; var saveSession = function(){var o = session;var sSession = objectToString(o); Ext.Ajax.request({method: "POST",params: {clientState : sSession},url: settings.sessionPostUrl});} window.onunload = saveSession; //load data from the server on loadvar loadSession = (function(){

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->