-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
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 resourceMap<String, Object>
: the model to use to render the viewString 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 theApplicationContext
that allows to retrieve it) - the view
Locale
- a
Function<String, String>
that allows the render function to callScriptTemplateView#getTemplate(String)
I see mainly 2 ways to support that:
-
We could be possible leverage
setExposeContextBeansAsAttributes()
orsetExposedContextBeanNames()
to access to context beans and expose them via model attributes. -
We could transform the 3rd parameter passed to the script function (currently
String url
) toRenderingContext
that would containsString url
,Locale locale
,ResourceBundleMessageSource messageSource
andFunction<String, String> templateLoader
properties. This would be a breaking change for people usingurl
butScriptTemplateView
is a rather feature, andurl
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:
- Add Kotlin ScriptTemplateView tests [SPR-15059] #19625 Add Kotlin ScriptTemplateView tests ("depends on")
- Expose view url to render function in ScriptTemplateView [SPR-13453] #18033 Expose view url to render function in ScriptTemplateView
- Update and improve script templating documentation [SPR-16447] #20992 Update and improve script templating documentation