s c h e m a t i c s : c o o k b o o k

/ Cookbook.WebDispatchOnLink

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Dispatch On a Link Being Clicked

Problem

You are writing a servlet in the PLT web server and want to choose an action based on which link was clicked.

Solution

If you want to embed the callbacks in an Xexpr, you can use send/suspend/callback, Simply insert your callbacks (functions of single argument, a request) in the Xexpr, and send/suspend/callback will replace them with appropriate URLs. For example:

(define (callback request)
   `(html (head (title "page two"))
          (body (h1 "page two"))))

(send/suspend/callback
   `(html (head (title "page one"))
          (body (h1 "page one")
                (p (a ((href ,callback)) "page two")))))

If you want access to the generated URLs, for example to use in Javascript, use send/suspend/dispatch. send/suspend/dispatch takes a function of a single argument. The argument, which by convention is named embed/url, is a function that consumes a callaback and returns a URL. For example:

(define (callback request)
   `(html (head (title "page two"))
          (body (h1 "page two"))))

(send/suspend/dispatch
  (lambda (embed/url)
   `(html (head (title "page one"))
          (body (h1 "page one")
                (p (a ((href ,(embed/url callback))) "page two"))))))

Discussion

It is not commonly realised that there can be more than one continuation per page. send/suspend/dispatch and send/suspend/callback show that this is possible. Both are provided by the servlet.ss module in the web-server collection.

A clumsy way to handle this situation is to append a parameter to the URL:

`(a ((href ,(string-append url "?arg=suchandsuch"))) "click here")

This is not recommended: the web server will add this parameter to all the next 'continuation' URL it gives you and you will have to manually strip it out.

The paper detailing send/suspend/dispatch (on which send/suspend/callback is built) is available from:

http://continue.cs.brown.edu/research/


Comments about this recipe

Contributors

-- NoelWelsh - 31 Aug 2004

-- PeteHopkins - 23 Nov 2004

-- DanielSilva - 11 Jan 2005

CookbookForm
TopicType: Recipe
ParentTopic: WebRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest