You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2006/03/16 17:40:46 UTC

[Jakarta-tapestry Wiki] Update of "Tapestry4Spring" by JarekWoloszyn

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: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org