Announcement Announcement Module
Collapse
No announcement yet.
Using VelocityLayoutView with VelocityViewResolver? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using VelocityLayoutView with VelocityViewResolver?

    Hi all,

    Is it possible to configure VelocityViewResolver to use VelocityLayoutView? As for VelocityToolboxView, setting the "toolboxConfigLocation" seems to do the trick. (I'm not sure if this implementation is a good idea, though.)

    Setting the "viewClass" works only if you don't want to configure VelocityLayoutView.

    Will I have to subclass VelocityViewResolver, or am I overlooking something?

  • #2
    Re: Using VelocityLayoutView with VelocityViewResolver?

    Originally posted by shinobu
    Will I have to subclass VelocityViewResolver, or am I overlooking something?
    Well, here's what I've got so far:
    Code:
    import java.util.Locale;
    
    import org.springframework.beans.BeansException;
    import org.springframework.web.servlet.View;
    import org.springframework.web.servlet.view.velocity.VelocityLayoutView;
    import org.springframework.web.servlet.view.velocity.VelocityView;
    import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
    
    public class VelocityLayoutViewResolver extends VelocityViewResolver {
    
        private String layoutUrl = null;
        private String layoutKey = null;
        private String screenContentKey = null;
    
        public void setLayoutUrl(String layoutUrl) {
            this.layoutUrl = layoutUrl;
        }
    
        public void setLayoutKey(String layoutKey) {
            this.layoutKey = layoutKey;
        }
    
        public void setScreenContentKey(String screenContentKey) {
            this.screenContentKey = screenContentKey;
        }
    
        public VelocityLayoutViewResolver() {
            this.setViewClass(VelocityLayoutView.class);
        }
    
        @Override
        public void setToolboxConfigLocation(String toolboxConfigLocation) {
            // ugly hack because super overrides viewClass.
            // definitly would be cleaner if toolbox support also was a subclass.
            Class clazz = this.getViewClass();
            super.setToolboxConfigLocation(toolboxConfigLocation);
            this.setViewClass(clazz);
        }
    
        @Override
        protected View loadView(String viewName, Locale locale) throws BeansException {
            VelocityView view = (VelocityView) super.loadView(viewName, locale);
            if (this.layoutUrl != null) {
                ((VelocityLayoutView) view).setLayoutUrl(this.layoutUrl);
            }
            if (this.layoutKey != null) {
                ((VelocityLayoutView) view).setLayoutKey(this.layoutKey);
            }
            if (this.screenContentKey != null) {
                ((VelocityLayoutView) view).setScreenContentKey(this.screenContentKey);
            }
            return view;
        }
    
    }

    Comment


    • #3
      Re: Using VelocityLayoutView with VelocityViewResolver?

      For those of you interested, I posted the stuff to JIRA.
      http://opensource.atlassian.com/proj...browse/SPR-941

      Comment

      Working...
      X