20021118 Monday November 18, 2002

JSTL and Cookies Something I learned today about JSTL - you can use {cookie.cookieName.value}* to get the String value of a cookie. Cool stuff, I found it by looking in the JSTL In Action book I bought about a month ago. BTW, if you're going to buy the book, you can get if for $12 cheaper from Amazon.

Here's an example of how I used this new-found syntax in my project.

<c:if test="{cookie.style.value == 'widescreen'}">
  body {
    background-image: url(/images/bg-wide.gif);
  }
</c:if>*

I also implemented the stylesheet switcher from A List Apart today. Very cool stuff - although I did have to add an extra line in the setActiveStyleSheet function to create a cookie for title. The following code block is supposed to do this for me, but didn't seem to work on XP with the latest browsers.

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

Oh well, at least I got it to work and learned some more JSTL in the process!

* I tried using the real syntax with a preceeding $, but that didn't work too well, and Velocity puked with:

[VELOCITY ERROR: parsing weblog entry] 
  org.apache.velocity.exception.ParseErrorException: 
  Encountered ".cookieName.value}

Any ideas why? It brings up another question I've been meaning to ask - is it possible to use Velocity syntax that's similar to JSP to get parameters and such in my roller templates? Posted in The Web at Nov 18 2002, 02:11:06 PM MST 1 Comment

Comments:

The reason that Velocity choked on $cookie is that Velocity only exposes the objects that you tell it to expose. In the Roller page templates, the only object that we expose is the $macros object.

Posted by Dave Johnson on November 18, 2002 at 04:10 PM MST #

Post a Comment:
  • HTML Syntax: Allowed