03.07.06

Adding numbers to session variables

Posted in Updates, Tips at 5:38 pm by Todd Wilson

Up till now it’s been a pretty big pain to add a number to a session variable. Oftentimes you’ll have something like a page number that you need to increment as you loop through search results pages. The page number is usually stored as a String, and to increment it you normally have to cast it to an int, increment it, then cast it back to a String. Recently, though, we added a “session.addToVariable” method that makes this a lot quicker. Here’s the documentation on it:

  • addToVariable( String variable, int value ). Adds a value to a session variable. Session variables are generally stored as Strings, so it’s normally more difficult than it should be to simply add a number to one. This method takes the name of the variable, which can either hold a String or Integer, and adds a number to it. The number added to it can be positive or negative.
    example: session.addToVariable( "PAGE_NUM", 1 );

Much simpler than the previous way. This will be part of our upcoming 2.7 release (any day now!), but if you’d like to make use of it right now you can simply upgrade to the latest pre-release version (2.6.0.6a).

del.icio.us:Adding numbers to session variables digg:Adding numbers to session variables spurl:Adding numbers to session variables wists:Adding numbers to session variables simpy:Adding numbers to session variables newsvine:Adding numbers to session variables blinklist:Adding numbers to session variables furl:Adding numbers to session variables reddit:Adding numbers to session variables fark:Adding numbers to session variables blogmarks:Adding numbers to session variables Y!:Adding numbers to session variables smarking:Adding numbers to session variables magnolia:Adding numbers to session variables segnalo:Adding numbers to session variables

Leave a Comment