-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore support for Freemarker request parameters and taglibs now that it supports Jakarta #30186
Comments
RequestParameters
in FreeMarker template after upgrade to Spring Framework 6
Hello @anabright , |
yes, I upgraded to SpringBoot 3.0.2 as parent and Freemarker had a hash for RequestParameters which doesn't exist anymore. From the Freemarker docs: Those RequestParameters could be accessed directly in your template, for example: As I'm working in a legacy project from waaaay back, I was hoping to find a more elegant way rather than getting the parameter from the servletRequest and adding it as an attribute to my model. |
I see that the issue is more than just not supporting the jakarta.* |
use spring-boot 3.1.2 use url: template code: controller code: { List listString=new ArrayList(); listString.add("a"); listString.add("b"); listString.add("c"); listString.add("d"); listString.add("e"); request.setAttribute("listString",listString); return "test20"; } run result : 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</#if>. (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):
[in template "test20.ftlh" at line 12, column 7] same question! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@anabright unfortunately, there's nothing we can do here. Even the latest version of Freemarker does not use Jakarta as far as I can tell. If you need to use the Servlet integration of Freemarker, only a change in freemarker can help here. |
I had this problem upgrading an old project from Spring 3 to Spring 6, by now we have no time to replace the technology used to render the views, so my solution was adding it as a new model attribute of FreeMarker. Replacing:
By, in backend:
and in frontend:
|
There's supposed to be a Freemarker release soon that supports jakarta. @snicoll maybe when it's out Spring can be updated to use the new version and add back the missing model attributes like |
@anabright it's not really actionable right now so please ping again when it's actually available and we'll have a look. |
@snicoll According to apache/freemarker#94 (comment)
I've checked version 2.3.33 and it includes |
It looks like Freemarker 2.3.33 was released in May 2024. Spring Framework 6 was released in November 2022. We could reintroduce this support in Spring Framework 6.2 at the earliest, so two entire minor versions into the 6th generation. Because we didn't get a lot of requests for this in the meantime, I'm reopening this enhancement request and adding it to our backlog. We'll prioritize this according to community demand. |
RequestParameters
in FreeMarker template after upgrade to Spring Framework 6
@anabright and others interested by this, this should be available shortly in |
@snicoll thanks for the nudge, unfortunately we migrated our freemarker templates to thymeleaf so we could upgrade our project to Spring Boot 3 and it's not in our plans to revert the changes. |
I tried freemarker 2.3.33, unfortunately the RequestParameters in the .ftl file still point to the freemarker.ext.servlet.* path instead of the freemarker.ext.jakarta.servlet.* path, how should I modify it? |
@yusuhua I can't find any reference to "freemarker.ext.servlet" in our codebase. If you're requesting assistance for your application, please do so on StackOverflow. If you believe you've found a bug in Spring Framework, please create a new issue with a minimal application that reproduces the problem. |
If anyone still encounters this issue, the workaround is to have a custom FreeMarkerView and manually add RequestParameters to the model:
(Don't forget to register it as a bean) In a similar vein, since the upgrade to Spring 6 and Freemarker 2.3.33, session attributes added like this This is the workaround:
Hope that helps. |
I just upgraded my app to Spring Boot 3.0.5 (and consequently Spring 6.0.7) and there seems to be something broken with
spring-boot-starter-freemarker
.In my Freemarker template, I have this line that used to work before the upgrade:
<div>${RequestParameters.myParam!}</div>
After the upgrade, I get this error when loading the template:
It seems like
RequestParameters
is not available anymore.I originally posted this issue in the spring-boot repo and @wilkinsona kindly pointed out that due to d84ca2b, there's no longer a RequestParameters entry in the model.
Are there plans to fix this?
Thanks!
The text was updated successfully, but these errors were encountered: