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
Support i18n and nested template loading in ScriptTemplateView render function [SPR-15064] #19630
Comments
Yevhenii Melnyk commented Not sure if the following stuff is appropriate here but I didn't want to open a new issue without discussion. So, the situation is following: I was trying to use two different template view resolvers in my Spring mvc app. For example, kotlin and javascript at the same time. Creation of 2 ViewResolver beans is not the problem. It seems impossible to use two Is there a way to use two scripting engines at the same time or this feature is not supported currently? |
Sébastien Deleuze commented Indeed this is currently not supported out of the box, but maybe you could make it works for your use case by extending |
Yevhenii Melnyk commented I'll leave the stackoverflow post regarding multiple configurers here in case somebody has a same question I've got. The implementation is really easy. Thank you Sébastien Deleuze. |
Sébastien Deleuze commented See also this related pull request for providing i18n support, I will try to provide a solution that fulfill that need too. |
Sébastien Deleuze commented Juergen Hoeller Could you please have a look to this pull request I have just submitted to say me if you are ok with such approach. This change would be breaking (on the script side, not on java side) for people using the third As you can see here the migration path is trivial. I preferred this option over using
I also choose to provide the |
Sébastien Deleuze commented Notice that this improvement allow this kind of Kotlin type-safe templates with i18n and nested template support:
|
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 viewTo achieve i18n support for messages and nested template loading, we need to provide these additional informations:
ResourceBundleMessageSource
instance (or theApplicationContext
that allows to retrieve it)Locale
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:
Referenced from: commits 7ff257c, 98642c7, 2d95199, 2a5d1b0
The text was updated successfully, but these errors were encountered: