/** * Overrides the normal rendering process in order to pre-process the Context, * merging it with the screen template into a single value (identified by the * value of screenContentKey). The layout template is then merged with the * modified Context in the super class. */ @Override protected void doRender(Context context, HttpServletResponse response) throws Exception { renderScreenContent(context); // Velocity context now includes any mappings that were defined // (via #set) in screen content template. // The screen template can overrule the layout by doing // #set( $layout = "MyLayout.vm" ) String layoutUrlToUse = (String) context.get(this.layoutKey); if (layoutUrlToUse != null) { if (logger.isDebugEnabled()) { logger.debug("Screen content template has requested layout [" + layoutUrlToUse + "]"); } } else { // No explicit layout URL given -> use default layout of this view. layoutUrlToUse = this.layoutUrl; } mergeTemplate(getTemplate(layoutUrlToUse), context, response); }
/** * The resulting context contains any mappings from render, plus screen content. */ private void renderScreenContent(Context velocityContext) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Rendering screen content template [" + getUrl() + "]"); } StringWriter sw = new StringWriter(); Template screenContentTemplate = getTemplate(getUrl()); screenContentTemplate.merge(velocityContext, sw); // Put rendered content into Velocity context. velocityContext.put(this.screenContentKey, sw.toString()); }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); // Use not-null checks to preserve VelocityLayoutView's defaults. if (this.layoutUrl != null) { view.setLayoutUrl(this.layoutUrl); } if (this.layoutKey != null) { view.setLayoutKey(this.layoutKey); } if (this.screenContentKey != null) { view.setScreenContentKey(this.screenContentKey); } return view; }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); // Use not-null checks to preserve VelocityLayoutView's defaults. if (this.layoutUrl != null) { view.setLayoutUrl(this.layoutUrl); } if (this.layoutKey != null) { view.setLayoutKey(this.layoutKey); } if (this.screenContentKey != null) { view.setScreenContentKey(this.screenContentKey); } return view; }
/** * Overrides the normal rendering process in order to pre-process the Context, * merging it with the screen template into a single value (identified by the * value of screenContentKey). The layout template is then merged with the * modified Context in the super class. */ @Override protected void doRender(Context context, HttpServletResponse response) throws Exception { renderScreenContent(context); // Velocity context now includes any mappings that were defined // (via #set) in screen content template. // The screen template can overrule the layout by doing // #set( $layout = "MyLayout.vm" ) String layoutUrlToUse = (String) context.get(this.layoutKey); if (layoutUrlToUse != null) { if (logger.isDebugEnabled()) { logger.debug("Screen content template has requested layout [" + layoutUrlToUse + "]"); } } else { // No explicit layout URL given -> use default layout of this view. layoutUrlToUse = this.layoutUrl; } mergeTemplate(getTemplate(layoutUrlToUse), context, response); }
/** * The resulting context contains any mappings from render, plus screen content. */ private void renderScreenContent(Context velocityContext) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Rendering screen content template [" + getUrl() + "]"); } StringWriter sw = new StringWriter(); Template screenContentTemplate = getTemplate(getUrl()); screenContentTemplate.merge(velocityContext, sw); // Put rendered content into Velocity context. velocityContext.put(this.screenContentKey, sw.toString()); }
/** * Overrides {@code VelocityView.checkTemplate()} to additionally check * that both the layout template and the screen content template can be loaded. * Note that during rendering of the screen content, the layout template * can be changed which may invalidate any early checking done here. */ @Override public boolean checkResource(Locale locale) throws Exception { if (!super.checkResource(locale)) { return false; } try { // Check that we can get the template, even if we might subsequently get it again. getTemplate(this.layoutUrl); return true; } catch (ResourceNotFoundException ex) { throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new NestedIOException( "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex); } }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); // Use not-null checks to preserve VelocityLayoutView's defaults. if (this.layoutUrl != null) { view.setLayoutUrl(this.layoutUrl); } if (this.layoutKey != null) { view.setLayoutKey(this.layoutKey); } if (this.screenContentKey != null) { view.setScreenContentKey(this.screenContentKey); } return view; }
/** * Overrides the normal rendering process in order to pre-process the Context, * merging it with the screen template into a single value (identified by the * value of screenContentKey). The layout template is then merged with the * modified Context in the super class. */ @Override protected void doRender(Context context, HttpServletResponse response) throws Exception { renderScreenContent(context); // Velocity context now includes any mappings that were defined // (via #set) in screen content template. // The screen template can overrule the layout by doing // #set( $layout = "MyLayout.vm" ) String layoutUrlToUse = (String) context.get(this.layoutKey); if (layoutUrlToUse != null) { if (logger.isDebugEnabled()) { logger.debug("Screen content template has requested layout [" + layoutUrlToUse + "]"); } } else { // No explicit layout URL given -> use default layout of this view. layoutUrlToUse = this.layoutUrl; } mergeTemplate(getTemplate(layoutUrlToUse), context, response); }
/** * The resulting context contains any mappings from render, plus screen content. */ private void renderScreenContent(Context velocityContext) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Rendering screen content template [" + getUrl() + "]"); } StringWriter sw = new StringWriter(); Template screenContentTemplate = getTemplate(getUrl()); screenContentTemplate.merge(velocityContext, sw); // Put rendered content into Velocity context. velocityContext.put(this.screenContentKey, sw.toString()); }