Announcement Announcement Module
No announcement yet.
Trying to use Velocity and JSP side-by-side Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to use Velocity and JSP side-by-side

    I am beginning a process of converting to Velocity for a Spring MVC application. Currently, all views are JSP/JSTL. I thought I could simply chain a UrlBasedViewResolver (with JstlView set as its viewClass), and a VelocityViewResolver. Unfortunately, the JSP view is resolved even when a velocity vm file exists for the requested view. Deleting the JSP version causes an error... the resolver tries to resolve the file even though it's gone.

    I think I know why this occurs. UrlBasedViewResolver javadoc says that it must be last in a chain, because it resolves regardless of wheter the file exists or not. VelocityViewResolver extends the UrlBasedViewResolver, so it has the same restriction..... so how can my view resolvers BOTH be last in a chain? I'd think "chaining" view resolvers would include some sort of failover (i.e. if the view cannot be resolved in one resolver... it goes on to the next).

    Can someone help me find a way to convert to Velocity one view at a time. I'd prefer not to convert all of my JSTL to VM in one fell swoop.

    Secondly, can someone comment on why the failover feature does not exist? Can I put this on a bug/request list? I'd be willing to work on my own solution and submit it.... but not if it's been left out on purpose.

  • #2
    A workable solution

    Although it's not ideal, I have found a solution that allows me to conver my views to velocity one at a time. I'm using the ResourceBundleViewResolver, with completely specified views in for each Velocity view I want to convert. When a viewname match is not found in the ResourceBundle ViewResolver, it fails over to the next ViewResolver, my JSP one. Here's an example entry from

    project/summary.class org.springframework.web.servlet.view.velocity.Velo cityView
    project/summary.url project/summary.vm
    project/summary.requestContextAttribute rc
    project/summary.exposeSessionAttributes true
    project/summary.dateToolAttribute date

    By the time I'm ready to switch to 100% velocity (using a UrlBasedViewResolver replacing my JSP one), this file will be a little messy for my tastes. Still curious as to why the UrlBasedViewResolver doesn't have the ability to failover to a viewResolver further in the chain. If it's a performance question of having to check that the file exists... then why not make it an optional feature that can be turned on in the bean definition?