#257

Scalate with Spring Portlet MVC

    • Created on: Fri, Sep 02 2011 (9 months ago)
    • Reported by: sebrichards
    • Assigned to: -
    • Milestone: -
    • Estimate: None/Small/Medium/Large None
    • Status: New
    • Priority: Low (4)
    • Component: scalate-spring-mvc
    • Permission type: Public
    Hi all.

    After attempting to use Scalate with Spring's Portlet MVC (using scalate-spring-mvc), I've discovered that because ServletConfig/PortletConfig and ServletContext/PortletContext don't share common ancestry, it's a non-starter.

    I have however adapted the TemplateEngineServlet to be compatible with Spring's InternalResourceViewResolver in a Portlet environment (see attached code). Although I'd like to contribute something like a scalate-spring-portlet-mvc module to compliment the scalate-spring-mvc one, I not sure how appropriate it would be given that my code doesn't use Spring's view lifecycle. By the same token, it appears to be impossible to extract the ServletConfig without using extensions proprietary to the Portal in use.

    Furthermore, it's obviously not appropriate to add this code to scalate-core to live with the original TemplateEngineServlet, as additional dependencies would be dragged in.

    I think at the very least I could write up some documentation for this, especially if my code can't be added to Scalate in some way.

    Thanks for listening!

    import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
    
    import org.fusesource.scalate.servlet.TemplateEngineServlet
    
    import org.springframework.web.servlet.ViewRendererServlet
    import org.springframework.web.servlet.view.InternalResourceView
    
    /**
     * Allow the TepmlateEngineServlet to be used in a
     * Spring Portlet MVC environment.
     *
     * More specifically, it maps the view path correctly.
     *
     * @author Seb Richards
     */
    class TemplateEnginePortletServlet extends TemplateEngineServlet {
    	
    	override def service(request: HttpServletRequest, response: HttpServletResponse) {
    		// Get the view attribute
    		val view = request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE).asInstanceOf[InternalResourceView];
    		
    		// Render using the view's URL
    		render(view.getUrl, request, response)
    	}
    	
    }
  • Followers
     
    Ico-users sebrichards 
     
    Attachments
    No attachments
    Associations
     
    No associations
    Activity
     
    User picture

          on Sep 06, 2011 @ 04:46pm UTC * By sebrichards

    Permission type changed from None to Public
    Time Expenditure
    Loading