• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Access request parameters in Freemarker templates

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using JForum and I wanted to access request parameters in Freemarker template files. I googled a bit and tried the followings without any luck.



They all return RequestParameters is undefined or args is undefined sort of errors.

I saw some questions like "How do you access request parameters in Freemarker templates using Spring MVC?" but I could not get help from those questions and answers.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Request parameters are not automatically available in the templates. You will need to set those that you need in your own code.
 
Adam Hun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah I see. Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason for this being, FreeMarker is a generic templating library (like Velocity), not a web-specific one like JSP - so it has no built-in provisions to support web apps.
 
Adam Hun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for further answer.

One more question though.

I also posted this on stackoverflow and got an answer saying it would break the separation of concerns if I used parameters on the MVC view layer.
How is that breaking the separation of concerns and how do I avoid that ?

If you could toss me some keywords or links, I'll do the rest of that.

I am not quite sure if I should make another thread for this one or not.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say that's a good follow-up that fits in here.

I think it's taking the "separation of concerns" idea too far to use it in this case - request and response are generally closely related, and you will frequently need to use some of the request parameters in rendering the response. If JForum used JSP then this would happen automatically. Since it uses FreeMarker, all parameters required in the response are set in the Action classes. Sure, the authors of JForum could have decided to add code that sets all request parameters all the time, but I agree with this limited approach simply for security reasons if nothing else (minimizing the attack surface in case of FreeMarker vulnerabilities).

By the way, if you post questions on multiple sites then you should https://coderanch.com/how-to/java/BeForthrightWhenCrossPostingToOtherSites for the reasons explained on that page, and provide links to those other discussions.
 
Adam Hun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah I see. I understand now.(well, as much as I can)

And oops, I didn't know that cross posting is considered a bad practice.
I normally don't do this though.

Again, thanks for that tip on keeping the community bulletin board neat. ;)

 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Hun wrote:And oops, I didn't know that cross posting is considered a bad practice.
I normally don't do this though.


Cross posting is fine. We just ask for a link to the other site. That way someone doesn't spend 15 minutes typing in a thoughtful answer only to find out the other site answered it first (or vice versa).
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic