Using Spring Themes in Struts (or other non-Spring) Application Flows

June 30th, 2009 Prem Nagrath, Consultant  (email the author)

Think it’s a weird kind of question? Not for people who have worked (or are working) on applications that are moving from one framework to another. I happened to work on one such project where a transition from Struts to Spring MVC was being done over a few releases. Not unexpectedly, this approach of supporting two frameworks at the same time gave the development team its own share of interesting challenges. And one such issue was how to use a new technology i.e. Spring themes in both frameworks, of course we could choose not to use it in enhancements to legacy Struts based application flows but then that would have meant doing the enhancements twice.

As a solution to this problem, all you need to do is make sure that the Spring beans for ThemeResolver and ThemeSource that you have defined in your config file, are available as request attributes. In a regular Spring MVC application flow, this would be done by the Dispatcher servlet but since in non-Spring MVC flow the control does not go through it, any attempt to use Spring themes would throw an error.

You can add the above mentioned Spring beans to the request in a number of ways and one of them is adding code to do this in a filter. So after including these two lines in your servlet filter, you should be able to use Spring themes in your Action Servlets as well as your JSPs:

 

request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE,yourThemeResolverBean)

request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE,yourThemeSourceBean)

 

 

Entry Filed under: Agile and Development

Leave a Comment

Required

Required, hidden


5 + seven =

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed

© 2010-2012 Summa All Rights Reserved -- Copyright notice by Blog Copyright