WebWork + SiteMesh using FreeMarker - available variables in decorators
Vítor Souza <[email protected]>
| Newsgroups | gmane.comp.web.sitemesh.general |
|---|---|
| Message-ID | <1338149.1113309929972.JavaMail.os-j2ee@opensymphony01.contegix.com> |
OK... I did some experiments this weekend and here are my findings:
1) A SimpleHash is created in com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet and that is what's available in the decorator.
2) Given conclusion # 1, I have no idea why ${Request.requestURL} works, since it is not put into the SimpleHash object. Also, requestURL is the only call that works here. Matt, are you sure other request calls (such as ${Request.locale}) work for you?
3) So, the solution to my problem could be to include a reference to the request object, by simply adding to line 78 of FreemarkerDecoratorServlet: hash.put("req", request);. Is this something the developers find useful? Could I open a JIRA issue for it?
4) Adding the line above to FreemarkerDecoratorServlet, the following references work: ${req}, ${req.setAttribute('foo', 'bar')}, ${req.getAttribute('foo')}, ${req.removeAttribute('foo')}, ${req.contextPath}, ${req.requestURI}, ${req.requestURL}, ${req.session}. I'm using Tomcat 5.5.
5) ${req.parameterNames}, ${req.parameterMap} also work, returning EnumerationModel and SimpleHash respectively. ${req.getParameter('foo')} works if 'foo' is defined as a parameter (ex.: ?foo=bar in the QueryString).
6) The following didn't work, although there have corresponding methods in the request class: ${req.pathInfo}, ${req.queryString},
${req.isRequestedSessionIdValid()}, ${req.info}, ${req.parameterValues}.
So, I'll probably extend FreemarkerDecoratorServlet here and make it work as above. If you find useful to add this solution to SiteMesh, let me know and I'll open a JIRA issue.
Thanks a lot to everyone that replied and helped.
VÃtor Souza
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1355&messageID=4590#4590
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]