Skip to content
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

Invalid reference to RequestParameters in Freemarker after upgrade #34733

Closed
anabright opened this issue Mar 23, 2023 · 8 comments
Closed

Invalid reference to RequestParameters in Freemarker after upgrade #34733

anabright opened this issue Mar 23, 2023 · 8 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@anabright
Copy link

anabright commented Mar 23, 2023

I just upgraded my app to Spring Boot 3.0.5 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:

freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> RequestParameters  [in template "template.ftlh" at line 136, column 11]

----
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):
	- Failed at: ${RequestParameters.myParam!}  [in template "template.ftlh" at line 136, column 9]

It seems like RequestParameters is not available anymore.

Is there a fix in sight for this?
Any workarounds?

Thanks!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 23, 2023
@wilkinsona
Copy link
Member

Which version of Spring Boot were you using before the upgrade?

As far as I can remember, we haven't made many, if any, recent changes to our FreeMarker support. Once possibility is this change in Spring Framework.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 23, 2023
@anabright
Copy link
Author

I upgraded from 2.7.10. If I go back to it, it works again.
Not sure if the issue you linked is the cause, it doesn't seem to mention any changes to the availability of RequestParameters

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 24, 2023
@wilkinsona
Copy link
Member

Sorry, I should have linked more precisely. I meant the change that I described in spring-projects/spring-framework#29787 (comment). Due to spring-projects/spring-framework@d84ca2b, there's no longer a RequestParameters entry in the model. Can you please open a Spring Framework issue and comment here with a link to it?

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2023
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Mar 24, 2023
@startjava

This comment was marked as duplicate.

@startjava

This comment was marked as duplicate.

@startjava
Copy link

@wilkinsona

This comment was marked as resolved.

@doctore
Copy link

doctore commented May 1, 2024

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:

<#if RequestParameters['authfail']??>
  ...
</#if>

By, in backend:

@ModelAttribute("rawRequestParameters") 
public String getRequestParameters(HttpServletRequest request) {
  return ofNullable(request)
            .map(HttpServletRequest::getQueryString)
            .orElse("");
}

and in frontend:

<#if rawRequestParameters?? && rawRequestParameters == "authfail">
  ...
</#if>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants