|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
ReverseAJAX + DWRSpringServlet + injecting ServerContext into ServiceHi -
I have managed to successfully implement reverse AJAX using DWR. Now the next logical step for me is to make the service creation using Spring. I know that in order to user Spring I have to use DWRSpringServlet. But I am confused as to how my service would get ServerContext injected into it. Without using Spring I am able to provide ServerContext to my service class by: <init-param> <param-name>initApplicationScopeCreatorsAtStartup</param-name> <param-value>true</param-value> </init-param> for DWR Servlet. and I have the following entry in my dwr.xml: <dwr> <allow> <create creator="new" javascript="alertService" scope="application"> </create> <convert converter="bean" match="test.AlertVO" /> </allow> </dwr> and my service class has the following piece of code: - public class AlertService { private static ServerContext serverContext; int count = 0; /** * Constructor */ public AlertService() { if (serverContext == null) { WebContext webContext = WebContextFactory.get(); ServletContext servletContext = webContext.getServletContext(); serverContext = ServerContextFactory.get(servletContext); } All of these are working correct for reverse Ajax when I am not using Spring. But I am unsure as to: - A) How will I let Spring inject serverContext in my service class? Can I use DWRSpringServlet and set "initApplicationScopeCreatorsAtStartup" to "true" in web.xml? B) How will I define the Service and the Converter in applicationContext.xml. Given the fact that I do not have any method to expose. rather the service method is invoked by JMS. Basically how do I need to modify my current dwr.xml entries for DWR Spring entries in applicationContext.xml? If anyone needs more information, I am willing to provide the same. At this point in time, I am stuck without proper guidance. Best Regards- DNC |
|
|
Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into ServiceHave your spring bean implement the ServletContextAware interface (spring specific) to get a handle on the servlet context instead of using WebContextFactory.
2009/10/30 DNC1234 <devajyoti.c@...>
|
|
|
Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into ServiceYes we can use ServletContextAware interface, but I do not want to directly use Spring APIs within my codebase. I would rather use spring configuration XML for DI and object instantiation. So far I am looking into possible solutions but haven't come across anything yet.
As for the converting the DWR.xml entries to applicationContext.xml, given the example I previously stated would there if any change with regards to bean and converter entries? <dwr> <allow> <create creator="new" javascript="alertService" scope="application"> < paramname="class" value="test.AlertService"/ > </create> <convert converter="bean" match="test.AlertVO" /> </allow> </dwr> Best Regards, DNC
|
|
|
Re: Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into ServiceOk... WebContextFactory.get() will only work for threads that were initiated by a DWR call. So, when your object is instantiated by spring (at container startup) it will not work. However WebContextFactory.get() will work inside a remote DWR method call if that helps.
Take a look at the spring config section in the docs http://directwebremoting.org/dwr/server/integration/spring.html. Converters are configured withing the <dwr:configuration> section with tags that mimic dwr.xml and beans are exposed as DWR remoted services using <dwr:remote javascript="myBean"> inside your bean definitions. 2009/10/30 DNC1234 <devajyoti.c@...>
|
| Free embeddable forum powered by Nabble | Forum Help |