<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Weblog of Michael Cutler &#187; Jakarta Velocity</title>
	<atom:link href="http://blog.lobstertechnology.com/category/java/jakarta-velocity/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.lobstertechnology.com</link>
	<description>"I felt a great disturbance in the Force, as if millions of peers suddenly cried out in terror and were suddenly silenced."</description>
	<lastBuildDate>Tue, 17 Oct 2006 14:40:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Velocimacro &#8211; Generate a HTML Select box and its Options</title>
		<link>http://blog.lobstertechnology.com/2005/10/05/velocimacro-generate-a-html-select-box-and-its-options/</link>
		<comments>http://blog.lobstertechnology.com/2005/10/05/velocimacro-generate-a-html-select-box-and-its-options/#comments</comments>
		<pubDate>Wed, 05 Oct 2005 11:42:56 +0000</pubDate>
		<dc:creator>Michael Cutler</dc:creator>
				<category><![CDATA[Jakarta Velocity]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.lobstertechnology.com/2005/10/05/velocimacro-generate-a-html-select-box-and-its-options/</guid>
		<description><![CDATA[A quick and simple Velocimacro to generate HTML Select boxes and its Options; automatically selects the correct option based on the value given.]]></description>
			<content:encoded><![CDATA[<p>A quick and simple Velocimacro to generate HTML Select boxes and its Options; automatically selects the correct option based on the value given.</p>
<p>You can place this #macro anywhere in your Velocity templates but I used my global VM_global_library.vm file.</p>
<p><strong> Code </strong></p>
<div class="igBar"><span id="lcode-1"><a href="#" onclick="javascript:showPlainTxt('code-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-1">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#macro<span style="color:#006600; font-weight:bold;">&#40;</span> generateSelectBox $name $options $value <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;select name=<span style="color:#CC0000;">'$name'</span> value=<span style="color:#CC0000;">'$value'</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#foreach <span style="color:#006600; font-weight:bold;">&#40;</span> $option in $options <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #set<span style="color:#006600; font-weight:bold;">&#40;</span> $selected = <span style="color:#CC0000;">""</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #if <span style="color:#006600; font-weight:bold;">&#40;</span> $option == $value <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; #set<span style="color:#006600; font-weight:bold;">&#40;</span> $selected = <span style="color:#CC0000;">"selected='true'"</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #end</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;option value=<span style="color:#CC0000;">'$option'</span> $selected&gt;$option&lt;/option&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/select&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong> Example Usage </strong></p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#generateSelectBox<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC0000;">"enabled"</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">"Y"</span>,<span style="color:#CC0000;">"N"</span><span style="color:#006600; font-weight:bold;">&#93;</span> $form.<span style="">enabled</span> <span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The resulting HTML:</p>
<div class="igBar"><span id="lcode-3"><a href="#" onclick="javascript:showPlainTxt('code-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-3">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;select name=<span style="color:#CC0000;">'enabled'</span> value=<span style="color:#CC0000;">'N'</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;option value=<span style="color:#CC0000;">'Y'</span>&gt;Y&lt;/option&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;option value=<span style="color:#CC0000;">'N'</span> selected=<span style="color:#CC0000;">'true'</span>&gt;N&lt;/option&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/select&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Addendum</strong></p>
<p>11th November 2005 : Thanks to MATT for pointing out the <a href='http://freemarker.sourceforge.net/'>FreeMarker</a> template engine as a promising replacement for <a href='http://jakarta.apache.org/velocity/'>Velocity</a>. <img src='http://blog.lobstertechnology.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lobstertechnology.com/2005/10/05/velocimacro-generate-a-html-select-box-and-its-options/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Velocity if statement is type sensitive&#8230;</title>
		<link>http://blog.lobstertechnology.com/2005/07/26/velocity-if-statement-is-type-sensitive/</link>
		<comments>http://blog.lobstertechnology.com/2005/07/26/velocity-if-statement-is-type-sensitive/#comments</comments>
		<pubDate>Tue, 26 Jul 2005 13:09:21 +0000</pubDate>
		<dc:creator>Michael Cutler</dc:creator>
				<category><![CDATA[Jakarta Velocity]]></category>

		<guid isPermaLink="false">http://blog.lobstertechnology.com/2005/07/26/velocity-if-statement-is-type-sensitive/</guid>
		<description><![CDATA[doh!]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong></p>
<p>I discovered that comparisons in Velocity <cite>if</cite> statements are type-sensitive the hard way.</p>
<p>For example, I am trying to display the 'selected' option in a html <cite>&lt;SELECT&gt;</cite> object. The list of possible values is <cite>$list</cite>, each is a simple 'NameValuePair' value object { String name, String value }.</p>
<p>The object I am editing in this form is <cite>$obj</cite>, and the field I am testing against is <cite>$obj.typeId</cite> defined as a <cite>long</cite>.</p>
<div class="igBar"><span id="lcode-4"><a href="#" onclick="javascript:showPlainTxt('code-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-4">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;select name=<span style="color:#CC0000;">'typeId'</span> value=<span style="color:#CC0000;">'$!{obj.typeId}'</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#foreach <span style="color:#006600; font-weight:bold;">&#40;</span> $item in $list <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #if <span style="color:#006600; font-weight:bold;">&#40;</span> $item.<span style="">value</span> == $obj.<span style="">typeId</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;option value=<span style="color:#CC0000;">'$item.value'</span> selected=<span style="color:#CC0000;">'true'</span>&gt;$item.<span style="">name</span>&lt;/option&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #else </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;option value=<span style="color:#CC0000;">'$item.value'</span>&gt;$item.<span style="">name</span>&lt;/option&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #end</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/select&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>However, the <cite>if</cite> statement on line 3 is actually comparing a <cite>String</cite> to a <cite>long</cite> which are of course never going to be equal.</p>
<p><strong>Solution</strong></p>
<p>The easiest work around in this case was to convert the <cite>$obj.typeId</cite> into a String before the comparison.</p>
<div class="igBar"><span id="lcode-5"><a href="#" onclick="javascript:showPlainTxt('code-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-5">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;select name=<span style="color:#CC0000;">'typeId'</span> value=<span style="color:#CC0000;">'$!{obj.typeId}'</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#set <span style="color:#006600; font-weight:bold;">&#40;</span> $typeId = <span style="color:#CC0000;">"$!{obj.typeId}"</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#foreach <span style="color:#006600; font-weight:bold;">&#40;</span> $item in $list <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #if <span style="color:#006600; font-weight:bold;">&#40;</span> $item.<span style="">value</span> == $typeId <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;option value=<span style="color:#CC0000;">'$item.value'</span> selected=<span style="color:#CC0000;">'true'</span>&gt;$item.<span style="">name</span>&lt;/option&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #else </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;option value=<span style="color:#CC0000;">'$item.value'</span>&gt;$item.<span style="">name</span>&lt;/option&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #end</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/select&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Any comments / feedback welcomed <img src='http://blog.lobstertechnology.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lobstertechnology.com/2005/07/26/velocity-if-statement-is-type-sensitive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Velocity Templates and Newlines</title>
		<link>http://blog.lobstertechnology.com/2005/07/21/velocity-templates-and-newlines/</link>
		<comments>http://blog.lobstertechnology.com/2005/07/21/velocity-templates-and-newlines/#comments</comments>
		<pubDate>Thu, 21 Jul 2005 21:13:24 +0000</pubDate>
		<dc:creator>Michael Cutler</dc:creator>
				<category><![CDATA[Jakarta Velocity]]></category>

		<guid isPermaLink="false">http://blog.lobstertechnology.com/?p=21</guid>
		<description><![CDATA[A short article on how to use newlines, carriage returns and other special characters in Velocity Templates]]></description>
			<content:encoded><![CDATA[<p>If you're reading this article you've probably encounted the same problem as I have. I was trying to put a newline '\n' character in the value of a variable in a Velocity template.</p>
<p><strong>Attempt 1:</strong></p>
<p>I assumed \n would work...</p>
<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-6">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#if <span style="color:#006600; font-weight:bold;">&#40;</span> !$foo <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #set <span style="color:#006600; font-weight:bold;">&#40;</span> $foo = <span style="color:#CC0000;">"There was no foo set in the Context.<span style="color:#000099; font-weight:bold;">\n</span>Please do something about it."</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end </div>
</li>
</ol>
</div>
</div>
</div>
<p>
This produced <cite>There was no foo set in the Context.\nPlease do something about it.</cite> as the value of $foo.</p>
<p><strong>Attempt 2:</strong></p>
<p>I just thought this was worth a shot <img src='http://blog.lobstertechnology.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<div class="igBar"><span id="lcode-7"><a href="#" onclick="javascript:showPlainTxt('code-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-7">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#if <span style="color:#006600; font-weight:bold;">&#40;</span> !$foo <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #set <span style="color:#006600; font-weight:bold;">&#40;</span> $foo = <span style="color:#CC0000;">"There was no foo set in the Context.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">Please do something about it."</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end </div>
</li>
</ol>
</div>
</div>
</div>
<p>
And the template failed to compile</p>
<p><strong>Solution:</strong></p>
<p>Basically, the easiest way I found is to place the newline, carriage return or other special character in the context.</p>
<div class="igBar"><span id="ljava-8"><a href="#" onclick="javascript:showPlainTxt('java-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-8">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> Template handleRequest<span style="color: #66cc66;">&#40;</span> HttpServletRequest request, HttpServletResponse response, <a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context <span style="color: #66cc66;">&#41;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #006600;">context</span>.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"nl"</span>, <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span> <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; context.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"cr"</span>, <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\r</span>"</span> <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And in your template:</p>
<div class="igBar"><span id="lcode-9"><a href="#" onclick="javascript:showPlainTxt('code-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-9">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#if <span style="color:#006600; font-weight:bold;">&#40;</span> !$foo <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; #set <span style="color:#006600; font-weight:bold;">&#40;</span> $foo = <span style="color:#CC0000;">"There was no foo set in the Context.${nl}Please do something about it."</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#end </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Maybe not the best solution but it works for me. If you expect to use it across your entire application I suggest you override <cite>VelocityServlet.createContext</cite> in your Servlet to add these characters to every context in your application.</p>
<p><strong>Example:</strong></p>
<div class="igBar"><span id="ljava-10"><a href="#" onclick="javascript:showPlainTxt('java-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-10">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> createContext<span style="color: #66cc66;">&#40;</span> HttpServletRequest request, HttpServletResponse response <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context = super.<span style="color: #006600;">createContext</span><span style="color: #66cc66;">&#40;</span> request, response <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; context.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"nl"</span>, <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span> <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; context.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"cr"</span>, <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\r</span>"</span> <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> context;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lobstertechnology.com/2005/07/21/velocity-templates-and-newlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
