Skip to content

Support i18n and nested template loading in ScriptTemplateView render function [SPR-15064] #19630

@spring-projects-issues

Description

@spring-projects-issues

Sébastien Deleuze opened SPR-15064 and commented

The render function called by ScriptTemplateView has currently 3 parameters provided:

  • String template: the content of the template resource
  • Map<String, Object>: the model to use to render the view
  • String url: the url of the 2 view

To achieve i18n support for messages and nested template loading, we need to provide these additional informations:

  • a ResourceBundleMessageSource instance (or the ApplicationContext that allows to retrieve it)
  • the view Locale
  • a Function<String, String> that allows the render function to call ScriptTemplateView#getTemplate(String)

I see mainly 2 ways to support that:

  1. We could be possible leverage setExposeContextBeansAsAttributes() or setExposedContextBeanNames() to access to context beans and expose them via model attributes.

  2. We could transform the 3rd parameter passed to the script function (currently String url) to RenderingContext that would contains String url, Locale locale, ResourceBundleMessageSource messageSource and Function<String, String> templateLoader properties. This would be a breaking change for people using url but ScriptTemplateView is a rather feature, and url is not widely used, so I consider this as an option in order to be consistent and provide such flexible mechanism for further needs + it provides these properties in a type-safe way which would be valuable for Kotlin JSR-223 support.


Issue Links:

Referenced from: commits 7ff257c, 98642c7, 2d95199, 2a5d1b0

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions