You should be able to get the WebApplicationContext from the
ServletContext. Here's how we do it in Spring MVC's LabelTag.java:
/**
* Get the validator resources from a ValidatorFactory defined
in the
* web application context or one of its parent contexts.
* The bean is resolved by type
(org.springframework.validation.commons.ValidatorFactory).
*
* @return ValidatorResources from a ValidatorFactory.
*/
private ValidatorResources getValidatorResources() {
// look in servlet beans definition (i.e. action-servlet.xml)
WebApplicationContext ctx = (WebApplicationContext)
pageContext.getRequest()
.getAttribute
(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
ValidatorFactory factory = null;
try {
factory = (ValidatorFactory) BeanFactoryUtils
.beanOfTypeIncludingAncestors(ctx,
ValidatorFactory.class, true, true);
} catch (NoSuchBeanDefinitionException e) {
// look in main application context (i.e.
applicationContext.xml)
ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext
(pageContext.getServletContext());
factory = (ValidatorFactory) BeanFactoryUtils
.beanOfTypeIncludingAncestors(ctx,
ValidatorFactory.class, true, true);
}
return factory.getValidatorResources();
}
Matt
On Dec 16, 2007, at 7:09 AM, Łukasz Bachman wrote:
Hello,
I need to fetch an item from my database and use it to render my
custom JSP tag.
I want to use my managers, already developed and tested. Unfortunately
I have no idea how to inject dependency into my tag, so I cannot use
beans declared in application context. I tried to do it manually,
creating new DAO object and new Manager, but it doesn't work (I don't
get any error message, but the page is blank). Is there anything I
need to keep in mind while searching for solution? Is there a way to
inject my Manager Bean into my Tag handler?
best regards,
Łukasz Bachman
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]