Hello,

I am constructing internal classes that extend "VelocityView" and override the doRender method. I am using this type of structure to build a templated layout dynamically. Here is the class that a content page would extend to draw it inside a layout, behind the scenes.

Code:
public abstract class PageUserView extends VelocityView {
	private String headerView;
	private String userInfoView;
	private String footerView;
	private String contentView;
	
	public PageUserView() {
		headerView = PageConstants.USER_VIEW_HEADER;
		userInfoView = PageConstants.USER_VIEW_USER_INFO;
		footerView = PageConstants.USER_VIEW_FOOTER;
	}
	
	public void setHeader(String headerView) {
		this.headerView = headerView;
	}
	
	public void setUserInfo(String userInfoView) {
		this.userInfoView = userInfoView;	
	}
	
	public void setFooter(String footerView) {
		this.footerView = footerView;
	}
	
	public void setContent(String contentView) {
		this.contentView = contentView;
	}
	
	protected abstract VelocityContext populatePage(); 
	
	@Override
	protected void doRender(Context context, HttpServletResponse response) throws Exception {
		VelocityContext skeletonContext = new VelocityContext();
		try {
			skeletonContext.put("header", getTemplate(headerView).toString());
			skeletonContext.put("user-info", getTemplate(userInfoView).toString());
			skeletonContext.put("footer", getTemplate(footerView).toString());

			if (StringUtils.isBlank(contentView)) {
				skeletonContext.put("content", "");
			} 
			else {
				Template contentTemplate = getTemplate(contentView);
				StringWriter writer = new StringWriter();
				contentTemplate.merge(populatePage(), writer);
				skeletonContext.put("content", writer.toString());
			}
			
			Template skeletonTemplate = getTemplate(PageConstants.USER_VIEW_SKELETON);
			
			StringWriter writer = new StringWriter();
			skeletonTemplate.merge(skeletonContext, writer);
			
			response.setContentType("text/html");
			response.getWriter().write(writer.toString());
		} 
		catch (Exception e) {
			throw new UnsupportedOperationException("Invalid templates -- " + e.getMessage(), e);
		}
	}
}
My question is two-fold. First of all, am I extending "VelocityView" in a way that it could be called properly when returning a ModelAndView from a spring controller?

And second, is there an easier way to programmatically create velocity layouts like this?

Any advice would get me farther. Thanks!