Global properties

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Global properties

Cesarvv
Hello.

The docs say if we have a template a.html the messages go in a.properties or a_en.properties.

That I want to use in the template a.html and b.html. What properties file does it go in? Is there a global properties file I can create or can I configure Thymeleaf to load a global properties file?

I'm going by these docs:

http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#messages

It seems like this would be a thing that this would support...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Global properties

Emanuel
Administrator
I took a look at the javadocs for the StandardMessageResolver class (the thing that finds properties files based on template names), and the Thymeleaf 3 one talks about being able to add defaults via this setDefaultMessages(Properties) method (http://www.thymeleaf.org/apidocs/thymeleaf/3.0.3.RELEASE/org/thymeleaf/messageresolver/StandardMessageResolver.html).

The Thymeleaf 2.1 javadocs aren't as detailed, but the class does have a setDefaultMessages(Properties) method which hopefully can do the same thing?  I think if you add some code to add your global properties files via that method at the startup of your application, you might get what you're after.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Global properties

Cesarvv
Thanks, this is my code:

...
TemplateEngine templateEngine=new TemplateEngine();
       
StandardMessageResolver standardMessageResolver = new StandardMessageResolver();
Properties defaultProps = new Properties();
FileInputStream in = FileInputStream("global.properties");
defaultProps.load(in);
in.close();
standardMessageResolver.setDefaultMessages(defaultProps);
templateEngine.setMessageResolver(standardMessageResolver);

templateEngine.setTemplateResolver(tr);
...

Loading...