Does anyone know how to use a custom ThemeSource in spring? I have seen many examples on how to use themes with property files using ResourceBundleThemeSource. Yet I have seen nothing on how to use hibernate to store vairous properties (such as a single css property) , read the properties with a custom ThemeSource and still be able to use the spring theme tags in the jsp.
I know I can create a controller and fetch these properties from the database with hibernate but I am more interested on knowing how to do this with Spring’s ThemeSource implementation.
If anyone has any ideas or examples I’d appreciate it.
Thanks
To use themes in your web application, you must set up an implementation of the
org.springframework.ui.context.ThemeSourceinterface. To use a custom ThemeSource implementation you can register a bean in the application context with the reserved namethemeSource. The web application context automatically detects a bean with that name and uses it.Here is the
ThemeSourceinterface:The only dark horse here is a
Themetype, which in fact is nothing more than:And in fact there is already a convenience implementation of
Themetype from Spring => SimpleThemeNotice that ThemeSource expects a Spring’s MessageSource, which means that theme attributes that are stored in a database, in your case, would need to be “converted” to be used with a
MessageSourceinterface.You can either write your own
DatabaseDrivenMessageSource, or just take it from hereNow, having all these variables in place, here is a custom
DatabaseThemeSource( that will become athemeSourcebean ):