Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-tapestry Wiki" 
for change notification.

The following page has been changed by JarekWoloszyn:
http://wiki.apache.org/jakarta-tapestry/Tapestry4Spring

------------------------------------------------------------------------------
  
  NandaFirdausi: I've seen your implementation, and I like it too, just like 
your other code ;). I thing your implementation doesn't need spring listener 
anymore, am I right? If so, then the choice to the user is if they do have 
another spring wep application with nothing to do with tapestry, it's better to 
set the spring listener and do like this page says. If your web application is 
all tapestry based (with spring as back-end support), then your code looks 
cleaner for me ;) 
  
+ 
+ == Tapestry 4 (another solution) ==
+ 
+ JarekWoloszyn: Here is another solution for Tapestry4.
+ 
+ We need a helper class which will create WebApplicationContext for the 
ServletContext. Hivemind can't call factory methods (from 
WebApplicationContextUtils), so we create a POJO. Spring Context is re-created 
everytime we change ServletContext.
+ {{{
+ package org.your.application;
+ 
+ import javax.servlet.ServletContext;
+ 
+ import org.springframework.web.context.WebApplicationContext;
+ import org.springframework.web.context.support.WebApplicationContextUtils;
+ 
+ 
+ public class SpringContextFactory {
+     private ServletContext servletContext;
+     private WebApplicationContext appContext;
+     
+     public WebApplicationContext getAppContext() {
+         return appContext;
+     }    
+     
+     public ServletContext getServletContext() {
+         return servletContext;
+     }
+ 
+     public void setServletContext(ServletContext servletContext) {
+         this.servletContext = servletContext;
+         appContext = 
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
+     }     
+ }
+ }}}
+ 
+ Tapestry 4 has Spring integration out of the box. We must only say which 
BeanFactory should be used.
+ In hivemind.xml, we define a service-point for our helper class. This class 
takes ServletContext as parameter. 
+ We configure then Hivemind to use appContext member as spring-bean factory.
+ {{{
+ <?xml version="1.0"?>
+ <module id="app" version="1.0.0" package="org.your.application">
+   
+   <contribution configuration-id="hivemind.ApplicationDefaults">
+     <default symbol="hivemind.lib.spring-bean-factory" 
value="service-property:app.SpringContextFactory:appContext"/>
+   </contribution>
+   
+     <service-point id="SpringContextFactory">        
+         Create WebApplicatonContext for Spring
+         <invoke-factory>
+             <construct class="SpringContextFactory">
+                 <set-service property="servletContext" 
service-id="tapestry.globals.ServletContext"/>
+             </construct>
+         </invoke-factory>        
+         
+     </service-point>
+     
+ </module>
+ }}}
+ 
+ And that's all. Now you can use spring: prefix to access Spring beans:
+ {{{
+     @InjectObject("spring:DAOFactory")
+     public abstract DAOFactory getDao();
+ }}}
+ 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to