Monday, August 23, 2004, 10:45:16 AM, Thorsten Schleinzer wrote:
What? August 23?
Post by Thorsten SchleinzerHello,
When I open the URL
example.ftl?id=12345
And use
${id}
In the ftl I receive a "id undefined" error.
But both in the preprocessRequest and
preTemplateProcess in my FreemarkerServlet
the call
request.getParameter("id")
returns the correct value.
Any hints why it is not passed to the template?
[snip]
FreeMarker is an MVC-ish technology, so I always thought that exposing
highly technical and cleanly MVC controller related stuff to templates
as HTTP request parameters is a bad idea. If somebody wants to follow
that style, then he can use JSP model 1 (or traditional PHP, ASP, etc.),
where you can use powerful Java language snippets. The point of "stupid
simple" page template techniques as FreeMarker, Velocity or WebMacro are
exactly that you move these technical things into Java "action" classes
or methods, and the template only deals with the displaying of the data
that the "action" has already prepared for it.
What you can access as top-level variables in templates are the
*attributes* of the HttpServletRequest, not the parameters. Maybe you
have confused these after reading pgui_misc_servlet.html. Attributes are
created by your Java code (the "action"), and not by the visitor (who
can send whatever parameters to the server).
But, of course it is possible to access the request params directly,
maybe Attila will tell if the FreemarkerServlet has such built in
feature. If it doesn't, just create a TemplateHashModel implementation
that wraps a HttpServletRequest and exposes it parameters as items in
the hash, and drop it into the data model. But I still recommend you to
read the ID parameter in the Java code, and expose its value as the
variable "id", rather than give the templates access to the request
parameters.
--
Best regards,
Daniel Dekany
____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu