Scoped WebApplication Beans

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 11:16 AM
I would like to be able to have scoped beans for Alfresco WebApplication Context from a servlet (not faces).
In order to get it to work I had to do the following:
In the web.xml, add the following:
In my module-context.xml, add the following (Note I added 2.0 to my DOCTYPE):
and get the bean with the following:
It works but I am surprised Alfresco does not already support it. Am I missing something? I realized you can do it in the Faces Container, but I need to be able to scope my beans it from a servlet.
In order to get it to work I had to do the following:
In the web.xml, add the following:
<web-app> … <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> …</web-app>
In my module-context.xml, add the following (Note I added 2.0 to my DOCTYPE):
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"><beans>… <bean id="PageRequestState" class="com.tlhc.wc.website.PageRequestState" scope="request" > … </bean></beans>
and get the bean with the following:
WebApplicationContext wc = RequestContextUtils.getWebApplicationContext(request, sc); PageRequestState prs = (PageRequestState)wc.getBean(PageRequestState.PAGE_REQUEST_STATE);
It works but I am surprised Alfresco does not already support it. Am I missing something? I realized you can do it in the Faces Container, but I need to be able to scope my beans it from a servlet.
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2009 06:06 AM
nobody from Alfresco can answer this question?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2009 05:31 PM
Just to share how I do it.
Before using the scoped proxy you need to have the proxy bound to the thread. The Spring's servlet listener or the filter does exactly this :
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq));
and it works in alfresco where you can use a bean with aop.
<bean id="jibe.repo.SearchResultsProvider" class="com.icodix.jibe.repo.dataprovider.SearchResultsGridProvider" parent="jibe.GridDataProvider"
scope="session">
<aop:scoped-proxy/>
</bean>
Before using the scoped proxy you need to have the proxy bound to the thread. The Spring's servlet listener or the filter does exactly this :
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq));
and it works in alfresco where you can use a bean with aop.
<bean id="jibe.repo.SearchResultsProvider" class="com.icodix.jibe.repo.dataprovider.SearchResultsGridProvider" parent="jibe.GridDataProvider"
scope="session">
<aop:scoped-proxy/>
</bean>
