[stringtemplate-interest] Multimethods

Harry Karadimas harry.karadimas at hmn.aphp.fr
Fri Nov 14 06:59:11 PST 2008


Well, it WOULD work on tomcat, where you could somehow extract
the session id and append it to the url, BEFORE the "?" (it's a
path parameter). However this is not the recommended way to do
it, as it is the web application server who decides if the link
is part of the site or not (links to 1 of several machines in a cluster,
with session attributes in a database, for example). If the machine
does not take part to the session, it does not need an jsessionid.

My approach does the job; the programmer does not have to guess & run
every possible url through the response.encodeURL method, and the view author
just has to say " ;format="url" ". What I was just suggesting
is that you could have some sort of "filters" or "handlers" that
transform something into something else, using an operator, and
parameters outside the view.
If I could write $url("http://myserver/foo/bar?next="+i)$
it would feel more natural than 
${http://myserver/foo/bar?next=$i$};format="url"$
In both approaches I would have to set the Response object before
the call to the template, so that encodeURL can be called during
rendering.

It's computation indeed; but the view author has no control over
it except that he calls it. Just as you declare a "format" or
a "renderer", you can declare an "operator handler", you can pass
parameters to before calling the template.
I understand if you consider that a bit risky; I just raised the
question because I thought it could be interesting. I don't feel
it breaks MVC separation; except if you consider that there should
be no control of the moment you use a particular template (i.e. arbitrary
template caching & reuse).

Harry

______________________________________________________________________
Dr Harry Karadimas,  Medecin Ingenieur
resp. Recherche et Developpement, Administration Wintel
Departement d'Information Hospitalier (DIH)
C.H.U. Albert Chenevier - Henri Mondor 
51, av. du Marechal de Lattre de Tassigny               94010  CRETEIL
tel : (00 33 1) 49 81 21 79                fax : (00 33 1) 49 81 27 08
secr.: (00 33 1) 49 81 23 82         m.el.:harry.karadimas at hmn.aphp.fr

-----Message d'origine-----
De : Terence Parr [mailto:parrt at cs.usfca.edu] 
Envoyé : jeudi 13 novembre 2008 19:32
À : Harry Karadimas
Cc : stringtemplate-interest at antlr.org
Objet : Re: [stringtemplate-interest] Multimethods


On Nov 12, 2008, at 6:24 AM, Harry Karadimas wrote:

> Yes, except for one little nasty requirement of Java Servlets :  
> session
> encoding
> as a path parameter. If a user turns cookies off (which happens in our 
> hospital, rather by mistake, but our mission - critical sites must 
> continue to function), the Servlet container must append an url path 
> parameter (which is different from a request parameter) named 
> jsession_id. The requirement for java servlets is that every URL must 
> be coded using response.encodeURL(String url).

Ah.  Perhaps then you simply need to pass in the session object to the template
and then the link template can encode that in the URL.

> (see
> http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/Ht
> tpServlet
> Response.html#encodeURL(java.lang.String)
> )
>
> That, unfortunately, is computation.

And definitely related to the controller not the view.

> And by design it gets very difficult
> to do in st. And coding every link in the controller makes things 
> really too tedious for the programmers, and too restrictive for the 
> view authors.

If you pass in session as an attribute than any template enclosed in your page
can see that attribute through dynamic scoping. your template could be

blog_post(m,d,y) ::= "/y/m/d&sessionid=<session.ID>"

or whatever the field of the session is. would that work?

Ter



More information about the stringtemplate-interest mailing list