Good morning, looks like these nasty integration problems :-)
Not sure if I’m qualified to help (FreeMarker rookie) but I had my share of integration problems * Can you access the HTTP request in general in you FreeMarker view or do you have problem access the value you set in the servlet filter? * If you see the HTTP request but not the value than there is something wrong with your HTTP session handling * It is sometimes hard to know what is in the final data model you are going to use - I recently found https://github.com/ratherblue/freemarker-debugger/ * Depends on your problem at hand but you can avoid all this HTTP XXX handling in FTL and provide a nice to use data model yourself Thanks in advance, Siegfried Goeschl > On 25.02.2019, at 06:16, Harsha Thota <[email protected]> wrote: > > Hi, > > We have a jersey based web application. We use Apache Freemarker for the > front end web pages. We integrate the Freemarker in our application using > the jersey-mvc-freemarker. In our web app we register the > FreeMarkerMvcFeature.class in the ResouceConfig on Startup. In our java > code, we return a Viewable which gets rendered in the FTL. > > I have created a servlet Filter and added it in out web.xml. This filter > intercepts all the http requests. In the doFilter method of that Filter, I > am getting the HTTPSession from the HTTP request and setting an attribute > value. Say "myVal". > > myVal should now be set on the HTTPSession in the HTTPServletRequest. I am > not able to access this myVal in the FTL page. I tried doing a lot of > research and also posted the question in stack overflow[ > https://stackoverflow.com/questions/54835683/freemarker-httpsession-attribute-returning-null] > but I did not get any proper response. > > I have tried to do the following: > > I have updated Freemarker to the latest version: 2.3.28 > > I have also tried adding the servlet[ > https://freemarker.apache.org/docs/pgui_misc_servlet.html] mentioned in the > Freemarker documentation to my web.xml and tried the following ways to > access the myVal: > > ${Request.myVal} > > ${myVal} > > ${Request.Session.myVal} > > ${Session.myVal} > > All the above values are "null" and the below exception is thrown > > FreeMarker template error (DEBUG mode; use RETHROW in production!): The > following has evaluated to null or missing: ==> Request [in template > "home.ftl" at line 18, column 3] > > *---- Tip: If the failing expression is known to legally refer to something > that's sometimes null or missing, either specify a default value like > myOptionalVar!myDefault, or use <#if > myOptionalVar??>when-present<#else>when-missing. (These only cover the last > step of the expression; to cover the whole expression, use parenthesis: > (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack > trace ("~" means nesting-related): - Failed at: > ${Request.Session.user_privilages} [in template "home.ftl" at line 18, > column 1]* > > Please suggest on how I can access the http request in the FTL page. It > would be a great help for my project. > > Please help. Thank you. > Regards, > Harsha Thota > 1 (470)-535-2763 || [email protected] > https://www.linkedin.com/in/thotaharsha
