Scalate with Spring Portlet MVC
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!
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)
}
}
Leave a comment