Monday, April 07, 2008

Velocity Layout in Spring

Spring 2.5.2/Velocity 1.5

In web.xml, define org.springframework.web.servlet.DispatcherServlet as spring. Mapping *.xhtml to spring. I leave html for real html files.

In spring-servlet.xml, define

viewResolver class=org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver

  • viewClass = org.springframework.web.servlet.view.velocity.VelocityLayoutView
  • layoutUrl = layouts/mainlayout.vm
  • cache = true
  • suffix = .vm
  • exposeRequestAttributes = true
  • exposeSessionAttributes = true
  • exposeSpringMacroHelpers = true
  • dateToolAttribute = dateTool
  • numberToolAttribute = numberTool

velocityConfigurer class = org.springframework.web.servlet.view.velocity.VelocityConfigurer

  • resourceLoaderPath = WEB-INF/views
  • velocityProperties directive.foreach.counter.name = loopCounter
  • directive.foreach.counter.initial.value=0

Create a layout file, mainlayout.vm under WEB-INF/views/layouts. Put html, body, stylesheet stuff in. Note the stylesheet file shall sit outside WEB-INF. e.g. stylesheet href = "includes/main.css" means the main.css file sits at [web-root]/includes forlder.

Put $screen_content whereever you want.

In spring controller, return the ModelAndView name "dashboard", create a dashboard.vm file under WEB-INF/views.

In the dashboard.vm file, put any content in.

No comments: