Modified: velocity/site/production/tools/devel/view-layoutservlet.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/view-layoutservlet.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/view-layoutservlet.html (original) +++ velocity/site/production/tools/devel/view-layoutservlet.html Tue Jun 26 10:03:18 2018 @@ -214,36 +214,36 @@ h2:hover > .headerlink, h3:hover > .head <p><a href="apidocs/org/apache/velocity/tools/view/servlet/VelocityLayoutServlet.html">org.apache.velocity.tools.view.servlet.VelocityLayoutServlet</a></p> <h2 id="configuration-settings">Configuration Settings<a class="headerlink" href="#configuration-settings" title="Permanent link">¶</a></h2> <p>Three settings can be added to velocity.properties to control the VLS, or the following default values will be used:</p> -<div class="codehilite"><pre># Filepath for error template, -# relative to web application root directory -tools.view.servlet.error.template = Error.vm - -# Directory for layout templates, -# relative to web application root directory -tools.view.servlet.layout.directory = layout/ - -# Filepath of the default layout template -# relative to the layout directory -# NOT relative to the root directory of the webapp! -tools.view.servlet.layout.default.template = Default.vm<span class="nt"></sourcecode></pre></span> +<div class="codehilite"><pre><span class="c"># Filepath for error template,</span> +<span class="c"># relative to web application root directory</span> +<span class="na">tools.view.servlet.error.template</span> <span class="o">=</span> <span class="s">Error.vm</span> + +<span class="c"># Directory for layout templates,</span> +<span class="c"># relative to web application root directory</span> +<span class="na">tools.view.servlet.layout.directory</span> <span class="o">=</span> <span class="s">layout/</span> + +<span class="c"># Filepath of the default layout template</span> +<span class="c"># relative to the layout directory</span> +<span class="c"># NOT relative to the root directory of the webapp!</span> +<span class="na">tools.view.servlet.layout.default.template</span> <span class="o">=</span> <span class="s">Default.vm</sourcecode></pre></span> </pre></div> <h2 id="layouts">Layouts<a class="headerlink" href="#layouts" title="Permanent link">¶</a></h2> <p>Now, in your layout templates, the only thing you really need is the screen content reference. So an acceptable layout template could be:</p> -<div class="codehilite"><pre>$screen_content +<div class="codehilite"><pre><span class="p">$!</span><span class="nv">screen_content</span><span class="x"></span> </pre></div> <p>...but that would make this whole thing an idiotic waste of time. At the least, you'll probably want to do something along these lines:</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> - $screen_content -<span class="nt"></body></span> -<span class="nt"></html></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> + <span class="p">$</span><span class="nv">screen_content</span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> @@ -251,62 +251,59 @@ tools.view.servlet.layout.default.templa <h2 id="alternative-layouts">Alternative Layouts<a class="headerlink" href="#alternative-layouts" title="Permanent link">¶</a></h2> <p>VLS provides two ways to specify an alternate template for a requested page:</p> <ol> -<li> -<p><strong>Specify the layout in the request parameters</strong></p> +<li><strong>Specify the layout in the request parameters</strong></li> +</ol> <p>Just add the query string "layout=MyOtherLayout.vm" to any request params and the VLS will find it and render your screen within that layout instead of the default layout. It don't matter how you get the layout param into the query data, only that it's there.</p> -</li> -<li> -<p><strong>Specify the layout in the requested screen.</strong></p> -</li> +<ol> +<li><strong>Specify the layout in the requested screen.</strong></li> </ol> <p>In the requested screen, put a line like this:</p> -<div class="codehilite"><pre> #set( $layout = "MyOtherLayout.vm" ) - -This will direct the VLS to use "MyOtherLayout.vm" instead of "Default.vm". *Setting the layout in this fashion will override any layout set by the request parameters.* +<div class="codehilite"><pre><span class="cp">#</span><span class="nf">set</span><span class="p">(</span> <span class="p">$</span><span class="nv">layout</span> <span class="o">=</span> <span class="s2">"MyOtherLayout.vm"</span> <span class="p">)</span><span class="x"></span> </pre></div> +<p>This will direct the VLS to use "MyOtherLayout.vm" instead of "Default.vm". <em>Setting the layout in this fashion will override any layout set by the request parameters.</em></p> <h2 id="navigations-tiles-and-how">'Navigations', 'Tiles', and How<a class="headerlink" href="#navigations-tiles-and-how" title="Permanent link">¶</a></h2> <p>Those of you who are (or were) Turbine or Struts users will probably want to do more than just set the layout and screen content. You want to include arbitrary "tiles" or "navigations", right? Well, thanks to Velocity's built-in <code>#parse</code> directive, this is easy.</p> <p>First, create your "tile" as a separate template file like:</p> -<div class="codehilite"><pre><span class="nt"><div</span> <span class="na">id=</span><span class="s">"footer"</span><span class="nt">></span>I made this!<span class="nt"></div></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"footer"</span><span class="p">></span>I made this!<span class="p"></</span><span class="nt">div</span><span class="p">></span> </pre></div> <p>For creativity's sake, we'll pretend this code is in a file named "Footer.vm" that is located in the root of my webapp like my other non-layout templates.</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> -$screen_content +<span class="p">$</span><span class="nv">screen_content</span> -#parse('Footer.vm') +<span class="cp">#</span><span class="nf">parse</span><span class="p">(</span><span class="s1">'Footer.vm'</span><span class="p">)</span> -<span class="nt"></body></span> -<span class="nt"></html></span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> <p>Easy, eh?</p> <p>Now, what if you have a lot of different "footer" files and you want your screen to decide which one will be used? No problem! Do something like this:</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> -$screen_content +<span class="p">$</span><span class="nv">screen_content</span> -#parse( $screen_footer ) +<span class="cp">#</span><span class="nf">parse</span><span class="p">(</span> <span class="p">$</span><span class="nv">screen_footer</span> <span class="p">)</span> -<span class="nt"></body></span> -<span class="nt"></html></span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> -<p>and in your screen, just do `#set( $screen_footer = 'FooFooter.vm' ).\</p> +<p>and in your screen, just do <code>#set( $screen_footer = 'FooFooter.vm' )</code>.</p> <p>Remember, your #parsed footer template will have access to the same velocity context as your layout, which gets the screen's context once the screen is done with it. This lets you set variables for the layout and footer to use from your screens.</p> <h2 id="error-screen">Error Screen<a class="headerlink" href="#error-screen" title="Permanent link">¶</a></h2> <p>Ok, the idea here is pretty simple. If an uncaught exception or error is thrown at some point during the processing of your screen and layout, the error() method of the VLS is called. This overrides the default error() method of the VelocityViewServlet to render a template instead of hardcoded html.</p> @@ -330,13 +327,13 @@ $screen_content </tbody> </table> <p>In the event that a MethodInvocationException is behind the calling of error(), the root cause is extracted from it and dealt with as described above. But, since template reference behavior is partly at fault here, the VLS will also add the MethodInvocationException itself to the context as $invocation_exception. This allows you to discover the reference and method call that triggered the root cause. To get those, do something like this in your error template:</p> -<div class="codehilite"><pre>#if( $invocation_exception ) - oh joy! it's a MethodInvocationException! +<div class="codehilite"><pre><span class="cp">#</span><span class="nf">if</span><span class="p">(</span> <span class="p">$</span><span class="nv">invocation_exception</span> <span class="p">)</span><span class="x"></span> +<span class="x"> oh joy! it's a MethodInvocationException!</span> - Message: $invocation_exception.message - Reference name: $invocation_exception.referenceName - Method name: $invocation_exception.methodName -#end +<span class="x"> Message: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">message</span><span class="x"></span> +<span class="x"> Reference name: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">referenceName</span><span class="x"></span> +<span class="x"> Method name: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">methodName</span><span class="x"></span> +<span class="cp">#</span><span class="nf">end</span><span class="x"></span> </pre></div></div></div> <hr/> <div id="copyright">
Modified: velocity/site/production/tools/devel/view-servlet.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/view-servlet.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/view-servlet.html (original) +++ velocity/site/production/tools/devel/view-servlet.html Tue Jun 26 10:03:18 2018 @@ -257,6 +257,7 @@ h2:hover > .headerlink, h3:hover > .head <span class="nt"><param-value></span>/WEB-INF/tools.xml<span class="nt"></param-value></span> <span class="nt"></context-param></span> +::xml <span class="nt"><context-param></span> <span class="nt"><param-name></span>org.apache.velocity.properties<span class="nt"></param-name></span> <span class="nt"><param-value></span>/WEB-INF/velocity.properties<span class="nt"></param-value></span> @@ -269,11 +270,11 @@ h2:hover > .headerlink, h3:hover > .head <p>The default configuration specifies the location of a 'global' Velocimacro template. This file can contain macros which will be made available to all templates.</p> <p>The location of the configuration file may be specified in web.xml, but it is recommended the file be placed inside the hidden WEB-INF directory of the web application and named 'velocity.properties' which is where the VelocityViewServlet will look for it in the absence of any location specified in the web.xml. An example configuration file is included with the distribution.</p> <p>Please see the <a href="/engine/devel/user-guide.html">Velocity User's Guide</a> for more information on Velocity configuration.</p> -<div class="codehilite"><pre>velocimacro.library = /WEB-INF/VM_global_library.vm -velocimacro.permissions.allow.inline = true -velocimacro.permissions.allow.inline.to.replace.global = false -velocimacro.permissions.allow.inline.local.scope = false -velocimacro.context.localscope = false +<div class="codehilite"><pre><span class="na">velocimacro.library</span> <span class="o">=</span> <span class="s">/WEB-INF/VM_global_library.vm</span> +<span class="na">velocimacro.permissions.allow.inline</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">velocimacro.permissions.allow.inline.to.replace.global</span> <span class="o">=</span> <span class="s">false</span> +<span class="na">velocimacro.permissions.allow.inline.local.scope</span> <span class="o">=</span> <span class="s">false</span> +<span class="na">velocimacro.context.localscope</span> <span class="o">=</span> <span class="s">false</span> </pre></div> @@ -282,11 +283,11 @@ velocimacro.context.localscope = false <p>Think about asking our friend Jon to grab us a 'wrench' from a real toolbox. Jon just needs to know which wrench we want (metric, pipe, crescent etc,). He doesn't need to know what the wrench does nor what we are planning to do with it.</p> <p>The Velocity Toolbox works the same way, we must only specify which tool we want, and then the Velocity engine takes care of the rest by making any public method available to the template. For example, from the definitions below, the template could call <code>$wrench.size</code>.</p> <p><strong>PipeWrench.java</strong></p> -<div class="codehilite"><pre>public class PipeWrench { - public String getSize() { - return "Large Pipe Wrench!"; - } -} +<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">PipeWrench</span> <span class="o">{</span> + <span class="kd">public</span> <span class="n">String</span> <span class="nf">getSize</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="s">"Large Pipe Wrench!"</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">}</span> </pre></div> @@ -310,8 +311,8 @@ velocimacro.context.localscope = false </ul> <h4 id="tool-path-restrictions">Tool Path Restrictions<a class="headerlink" href="#tool-path-restrictions" title="Permanent link">¶</a></h4> <p>You can specify a restriction on the request URIs for which the tool will be available in the context using the "restrictTo" attribute of your tool configuration. It can be an exact request path (matching one page) or end with the <code>*</code> wildcard, meaning that incoming request paths need only start with the provided value for the tool to be available. For instance:</p> -<div class="codehilite"><pre><tool restrictTo="/catalog/*" - class="com.mycompany.tools.CatalogTool"/> +<div class="codehilite"><pre><span class="nt"><tool</span> <span class="na">restrictTo=</span><span class="s">"/catalog/*"</span> + <span class="na">class=</span><span class="s">"com.mycompany.tools.CatalogTool"</span><span class="nt">/></span> </pre></div> Modified: velocity/site/production/tools/devel/view-tag.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/view-tag.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/view-tag.html (original) +++ velocity/site/production/tools/devel/view-tag.html Tue Jun 26 10:03:18 2018 @@ -211,19 +211,19 @@ h2:hover > .headerlink, h3:hover > .head <p class="note">This page is still unfinished. For details on configuring the VelocityViewTag, you can follow most of the instructions for the <a href="view-servlet.html">VelocityViewServlet</a> and of course on the <a href="configuration.html">configuration pages</a>. <a href="index.html#Contribution">Help finishing this is welcome!</a> </p> <p>This is a JSP tag that allows you to use Velocity and VelocityTools from within a JSP page or tag. There are many ways to use this tag. This simplest is to have it process an external template using the current page context. Assuming you have a template called "foo.vm" that can be found by your resource loader(s) that looks like this:</p> -<div class="codehilite"><pre>Hello $!bodyContent World! +<div class="codehilite"><pre><span class="x">Hello </span><span class="p">$!</span><span class="nv">bodyContent</span><span class="x"> World!</span> </pre></div> <p>This tag can process that template by doing:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span><span class="x"></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> -<span class="x"><velocity:view template="foo.vm"/></span> +<span class="nt"><velocity:view</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">/></span> </pre></div> <p>VTL in the body of the tag:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view></span> #if( $date.E eq 'Friday' ) @@ -236,7 +236,7 @@ h2:hover > .headerlink, h3:hover > .head <p>or combine both by first processing the body of the tag, then inserting the results of that into the context for the separate template as $bodyContent:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">></span> #if( $date.E eq 'Friday' ) @@ -249,7 +249,7 @@ h2:hover > .headerlink, h3:hover > .head <p>You can also store the results of any of the options above into a variable of any name and scope (default scope is "page"):</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view</span> <span class="na">var=</span><span class="s">"foo"</span> <span class="na">scope=</span><span class="s">"request"</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">></span> #if( $date.E eq 'Friday' ) @@ -261,7 +261,7 @@ h2:hover > .headerlink, h3:hover > .head </pre></div> -<p>For more details, see the <a href="apidocs/org/apache/velocity/tools/view/jsp/VelocityViewTag.html">Javadoc</a> or the <a href="http://svn.apache.org/repos/asf/velocity/tools/trunk/src/main/java/META-INF/velocity-view.tld">TLD</a>.</p></div></div> +<p>For more details, see the <a href="apidocs/org/apache/velocity/tools/view/jsp/VelocityViewTag.html">Javadoc</a> or the <a href="http://svn.apache.org/repos/asf/velocity/tools/trunk/src/main/resources/META-INF/velocity-view.tld">TLD</a>.</p></div></div> <hr/> <div id="copyright"> Copyright © 2016 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.
