View Full Version : how to make Custom Tag to talk with Spring?
pagilan
Feb 8th, 2006, 06:36 AM
Hi,
I have struts in the web layer and spring in the business layer. Struts Action classes are integrated with spring framework using context loader plugin.
I need to write a custom tag library for my application( normal custom tags or extending Struts tags. ). I need this taglibrary to be integrated with spring to get some business data.
Can anyone pointout how to do this?
Thanks in advance
Agilan
matthewramella
Feb 8th, 2006, 08:18 AM
I recently attempted exactly what you're describing (i.e., inject Spring-based business services into my custom tags), but I did not have any luck, unfortunately. After searching the entire message board, I never found an elegent solution. I considered using the ClassPathXmlApplicationContext (can also use FileSystemXmlApplicationContext) to load up the beans, but decided against it. Anyhow, if you're really in bind, you might want to check out the classes mentioned above. Here's a link each API:
http://static.springframework.org/spring/docs/2.0-m2/api/org/springframework/context/support/ClassPathXmlApplicationContext.html
http://static.springframework.org/spring/docs/2.0-m2/api/org/springframework/context/support/FileSystemXmlApplicationContext.html
dhewitt
Feb 8th, 2006, 09:03 AM
You can use WebApplicationContextUtils.getWebApplicationContex t(ServletContext) to get hold of the current root application context.
Or you can extend RequestContextAwareTag, which gives you access to the RequestContext, from which you can get the ApplicationContext.
pagilan
Feb 9th, 2006, 08:45 PM
Thanks for the quick reply. This is exactly what I wanted.
Regards
Agilan
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.