WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 XTree usePersistence kills my tomcat session!, Rob, May 7, 2004
     Re:XTree usePersistence kills my tomcat session!, Rob, May 7, 2004
         Re:XTree usePersistence kills my tomcat session!, Erik Arvidsson, May 9, 2004

Subject: Re:XTree usePersistence kills my tomcat session! From: Rob Date: May 7, 2004

For anyone interested, I rewrote the getCookie and setCookie methods for the xTree script to only use 1 single cookie yet maintain persistence...if you read my email below that I submitted this morning, my session was getting invalidated because IE only allows for 20 cookies from the same domain and my tree had 56 branches and was trying to create 56 cookies plus my JSessionId and it was overwriting my JSessionId, which was in turn invalidating my session with my app server.  I couldn't get any help anywhere so I sat down and 8 hours later I have written something that uses onse single cookie.  Check it out...please leave comments or questions and if you see something wrong or something you think would work better than what I'm doing to make it more efficient...by all means! 

All you need to do is replace your existing WebFXCookie.prototype.setCookie and WebFXCookie.prototype.getCookie methods with the following code...just highlight those two methods and replace them with this code:

WebFXCookie.prototype.setCookie = function (nombre, value) {
  var oneCookie = this.getRealCookie( "oneCookie" );
  if ( oneCookie == null )
 oneCookie = "*" + nombre + "~" + value;
  else
  {
   var test = this.getCookie( nombre );
 if ( test != null ) {
   var start = oneCookie.indexOf( '*' + nombre + '~' );
   var end = oneCookie.indexOf( '*', start + 1 )
   if (end == -1) { end = oneCookie.length; }
   var temp = oneCookie.substr( 0, start );
   temp += oneCookie.substr( end );
   oneCookie = temp;
   oneCookie += "*" + nombre + "~" + value;
 }
 else
      oneCookie += "*" + nombre + "~" + value;
  }
  this.setRealCookie( oneCookie );
}

WebFXCookie.prototype.setRealCookie = function (value) {
  document.cookie = this.cookies = "oneCookie" + "=" + escape(value);
}

WebFXCookie.prototype.getCookie = function (key) {
  if (this.cookies) {
   var oneCookie = this.getRealCookie( "oneCookie" );
 if ( oneCookie == null ) { return null; }
    var start = oneCookie.indexOf('*' + key + '~');
    if (start == -1) { return null; }
    var end = oneCookie.indexOf("*", start + 1);
    if (end == -1) { end = oneCookie.length; }
    end -= start;
    var cookie = oneCookie.substr(start,end);
    return unescape(cookie.substr(cookie.indexOf('~') + 1, cookie.length - cookie.indexOf('~') + 1));
  }
  else { return null; }
}

WebFXCookie.prototype.getRealCookie = function (key) {
  if (this.cookies) {
    var start = this.cookies.indexOf(key + '=');
    if (start == -1) { return null; }
    var end = this.cookies.indexOf(";", start);
    if (end == -1) { end = this.cookies.length; }
    end -= start;
    var cookie = this.cookies.substr(start,end);
    return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
  }
  else { return null; }
}

In all my testing over the last 2 hours on my monsterous tree, things seem to be working just the way I hoped them to.  I hope this helps anyone else running into this same problem!

Rob Brueckmann

From: Rob
Sent: May 7, 2004
Subject: Re:XTree usePersistence kills my tomcat session!

If I set usePersistence to true and I log into my web application and I go to the screen that displays my multi-level tree and I click on the 'Expand All' link I've created that simly triggers the expandAll() function for the xtree, it expands the entire tree without a problem, but towards the bottom of the tree, the icons disappear and if I click on individual levels to expand and collapse after having expanded the entire tree, those icons disappear for those levels as well and if I try to go somewhere else in the web application, I get automatically sent back to my log in screen and am forced to log in again.  Does anyone know why the usePersistence feature would be killing my session?  Is there a fix for this?

Thanks for ANY help at all!

rlb





Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX