<?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"
	>

<channel>
	<title>Piraguablog</title>
	<atom:link href="http://www.piragua.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.piragua.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Fri, 13 Jun 2008 00:56:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Your Grails domain class has more properties than you think!</title>
		<link>http://www.piragua.com/2008/06/10/grails-domain-class-properties/</link>
		<comments>http://www.piragua.com/2008/06/10/grails-domain-class-properties/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 22:32:06 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://piragua.com/blog/?p=21</guid>
		<description><![CDATA[But you probably already knew that - things like &#8216;id&#8217;, &#8216;version&#8217; and &#8216;log&#8217; properties are added to every Grails domain class by the framework and are pretty obvious.  But there are a few more that might not be so familiar.
Take a look at this domain class:

class Book &#123;
    String name
   [...]]]></description>
			<content:encoded><![CDATA[<p>But you probably already knew that - things like &#8216;id&#8217;, &#8216;version&#8217; and &#8216;log&#8217; properties are added to every <a title="Grails" href="http://grails.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/grails.org');" target="_blank">Grails</a> domain class by the framework and are pretty obvious.  But there are a few more that might not be so familiar.</p>
<p>Take a look at this domain class:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy"><span style="color: #000000; font-weight: bold;">class</span> <span style="color: #aaaadd; font-weight: bold;">Book</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">String</span> name
    Author author
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Of course, it has a name and author, and a few more - if I print out <code>new Book().properties.each {println it}</code> the following are revealed (check out the one in <strong>bold</strong>):</p>
<ul>
<li>author:null</li>
<li><strong>authorId:null</strong></li>
<li>class:class Book</li>
<li>constraints:&#8230; (removed for brevity)</li>
<li>errors:org.springframework.validation.BeanPropertyBindingResult: 0 errors</li>
<li>id:null</li>
<li>log:org.apache.commons.logging.impl.Log4JLogger@de9e85</li>
<li>metaClass:groovy.lang.ExpandoMetaClass@47ec8e[class Book]</li>
<li>name:null</li>
<li>version:null</li>
</ul>
<p>I guess I understand where this is coming from (since Book has an Author) - but it tripped me up a little bit the other day when I was working with a domain builder.  The builder is pretty &#8216;dumb&#8217; - it basically builds domain classes based on attributes of a map that match up with attributes on a domain class.  So along came a new domain class:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy"><span style="color: #000000; font-weight: bold;">class</span> Author <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">String</span> name
    <span style="color: #aaaadd; font-weight: bold;">String</span> authorId
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>which just happens to contain an &#8216;authorId&#8217; (users wanted to capture an ID separately from the ID Hibernate generates).  When the builder checks the properties against the two domain classes - it finds a match in the Book class because of the &#8216;authorId&#8217; property and tries to set it - but BOOM!  &#8217;authorId&#8217; is a read-only property (as it should be).  No worries, it&#8217;s a quick fix - now the builder just checks to see if the property also has a setter - something like <code>if(dc.metaClass.hasProperty(dc, it)?.<strong>setter</strong>)</code> - and TADA, we&#8217;re back up and running.</p>
<p>Anyway, the next time you&#8217;re playing around in Grails console - give it a shot and take a look at the properties your domain classes have - you might be surprised what you find.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piragua.com/2008/06/10/grails-domain-class-properties/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The elusive HTML &#8216;id&#8217; attribute when using &#60;g:form&#62;</title>
		<link>http://www.piragua.com/2008/04/14/the-elusive-html-id-attribute-when-using/</link>
		<comments>http://www.piragua.com/2008/04/14/the-elusive-html-id-attribute-when-using/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 19:07:40 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://piragua.com/2008/04/14/the-elusive-html-id-attribute-when-using/</guid>
		<description><![CDATA[In most Grails tags, the usual HTML attributes get passed through to the output HTML, for example the &#8216;class&#8217; attribute below:

&#60;g:textField name=&#34;name&#34; class=&#34;inputField&#34; value=&#34;${book?.name}&#34; /&#62;
results in:
&#60;input type=&#34;text&#34; class=&#34;inputField&#34; name=&#34;name&#34; value=&#34;&#34; id=&#34;name&#34; /&#62;

I tried to do this with a g:form tag and passed in an &#8220;id&#8221; attribute so I could reference the form in javascript.  [...]]]></description>
			<content:encoded><![CDATA[<p>In most Grails tags, the usual HTML attributes get passed through to the output HTML, for example the &#8216;class&#8217; attribute below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g:textField</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;inputField&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${book?.name}&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
results in:
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;inputField&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></pre></div></div>

<p>I tried to do this with a g:form tag and passed in an &#8220;id&#8221; attribute so I could reference the form in javascript.  But you can&#8217;t pass an id attribute to the g:form tag because the &#8220;id&#8221; attribute is reserved for the id of the domain object you&#8217;re dealing with:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g:form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;save&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bookForm&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
results in:
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;/form/book/save/bookForm&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="font-weight: bold; color: black;">&gt;</span></span>
instead of this (like what I was hoping for):
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;/form/book/save&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bookForm&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span></pre></div></div>

<p>As a workaround I abandoned the g:form tag whenever I needed to pass through an &#8220;id&#8221; attribute and just wrote a standard HTML &lt;form&gt; tag instead&#8230;until I noticed that the &#8220;name&#8221; attribute of g:form is also output as the &#8220;id&#8221; in the generated HTML.  So now, I just write a g:form tag with a &#8220;name&#8221; attribute and end up with the result I&#8217;m looking for!  Here&#8217;s the example:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g:form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;save&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bookForm&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
results in:
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;/form/book/save&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bookForm&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bookForm&quot;</span> <span style="font-weight: bold; color: black;">&gt;</span></span></pre></div></div>

<p>&#8220;bookForm&#8221; shows up in the HTML code as both the name and the id of the HTML form tag.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piragua.com/2008/04/14/the-elusive-html-id-attribute-when-using/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using the showSource parameter trick with rendered templates</title>
		<link>http://www.piragua.com/2008/03/31/using-the-showsource-parameter-trick-with-rendered-templates/</link>
		<comments>http://www.piragua.com/2008/03/31/using-the-showsource-parameter-trick-with-rendered-templates/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 18:19:55 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://piragua.com/2008/03/31/using-the-showsource-parameter-trick-with-rendered-templates/</guid>
		<description><![CDATA[This is a follow-up to my previous post about using the showSource parameter in Grails.
If you&#8217;re using templates to keep DRY, you may need to pay attention to the details of the stack trace that show which GSP contains the error.  For instance, say my show.gsp renders a template like this:

&#60;g:render template=&#34;/person/personDetails&#34; bean=&#34;${person}&#34;/&#62;

If there&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to my previous post about <a href="http://http://piragua.com/2008/03/15/viewing-the-source-of-a-compiled-gsp-in-grails/" >using the showSource parameter in Grails</a>.</p>
<p>If you&#8217;re using templates to keep DRY, you may need to pay attention to the details of the stack trace that show which GSP contains the error.  For instance, say my show.gsp renders a template like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #66cc66;">&lt;</span>g:render template=<span style="color: #ff0000;">&quot;/person/personDetails&quot;</span> bean=<span style="color: #ff0000;">&quot;${person}&quot;</span>/<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>If there&#8217;s an error with the _personDetails.gsp, adding showSource to the URL of &#8220;show&#8221; (like this:  http://localhost:8080/[APP_NAME]/person/show/1?showSource) won&#8217;t actually do the trick.  That will show you the source of the show.gsp page, not the _personDetails.gsp page.  Look closely at the stacktrace and you&#8217;ll see the actual path to the GSP that threw the exception - in this case it&#8217;s grails_app_views_person__personDetails_gsp (which translates to grails-app/views/person/_personDetails.gsp).  If you change the URL to point directly at the GSP in question and then append the showSource parameter, (e.g. http://localhost:8080/[APP_NAME]/person/_personDetails.gsp?showSource) you&#8217;ll get the GSP source you&#8217;re looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piragua.com/2008/03/31/using-the-showsource-parameter-trick-with-rendered-templates/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Viewing the source of a compiled GSP in Grails</title>
		<link>http://www.piragua.com/2008/03/15/viewing-the-source-of-a-compiled-gsp-in-grails/</link>
		<comments>http://www.piragua.com/2008/03/15/viewing-the-source-of-a-compiled-gsp-in-grails/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 21:55:06 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://piragua.com/2008/03/15/viewing-the-source-of-a-compiled-gsp-in-grails/</guid>
		<description><![CDATA[So you&#8217;re working happily on your Grails application, coding away, being extremely productive until BOOM!  You get a Grails Runtime Exception error page like this when you hit a GSP:

What the heck?  Reading the stack trace you see that the exception is caused somewhere in a GSP:

You&#8217;ve found the error of course, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;re working happily on your Grails application, coding away, being extremely productive until BOOM!  You get a Grails Runtime Exception error page like this when you hit a GSP:</p>
<p><img src="/wp-content/uploads/2008/03/gre.jpg" alt="grails runtime error" height="363" width="601" /></p>
<p>What the heck?  Reading the stack trace you see that the exception is caused somewhere in a GSP:</p>
<p><img src="/wp-content/uploads/2008/03/errorLineNumber.jpg" height="104" width="578" /></p>
<p>You&#8217;ve found the error of course, it&#8217;s right there on line 33 of the grails-app/views/person/show.gsp.  Um, not quite.  If you look at line 33 of show.gsp you won&#8217;t find anything of consequence:</p>
<p>&lt;td valign=&#8221;top&#8221; class=&#8221;name&#8221;&gt;Name:&lt;/td&gt;</p>
<p>There isn&#8217;t any code on that line that could possibly cause a null pointer exception.  So then you realize - the line 33 the stack trace is referring to is the line in the compiled GSP!  But where oh where would that source for the GSP be?  You search in your ~/.grails directory but don&#8217;t find anything obvious there.  A couple fruitless google searches later and you start undoing your changes, one by one, until you find the line of code that caused your problem.  What if, you ask, there was an easy way to see the source of a compiled Grails GSP?  Then you find out:</p>
<p>there is.</p>
<p>When running in &#8220;development&#8221; mode (i.e. this trick doesn&#8217;t work in test or production or other environments), just append the parameter &#8220;showSource&#8221; to the URL (e.g. http://localhost:8080/[APP_NAME]/person/show/3?showSource) and TADA - you get the compiled source code:</p>
<p><img src="/wp-content/uploads/2008/03/showSource.jpg" height="363" width="705" /></p>
<p>Now you can figure out where line 33 is (I usually end up copying the source into an editor like TextMate that shows line numbers) and see what caused your error.  In this particular case, gender is null and when the GSP tries to obtain the &#8220;code&#8221; attribute on the &#8220;gender&#8221; property, it causes a NPE.</p>
<p><img src="/wp-content/uploads/2008/03/npe.jpg" height="183" width="469" /></p>
<p>Add a quick fix:<br />
person.gender?.code<br />
try the page again and everything&#8217;s hunky dory.</p>
<p>Thank you showSource parameter.  You just made my life oh so much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piragua.com/2008/03/15/viewing-the-source-of-a-compiled-gsp-in-grails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Accurate branch reports with Grails and Cobertura _1.8_</title>
		<link>http://www.piragua.com/2008/01/31/accurate-branch-reports-with-grails-and-cobertura-_18_/</link>
		<comments>http://www.piragua.com/2008/01/31/accurate-branch-reports-with-grails-and-cobertura-_18_/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 02:35:06 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://piragua.com/2008/01/31/accurate-branch-reports-with-grails-and-cobertura-_18_/</guid>
		<description><![CDATA[I&#8217;m trying to figure out why Cobertura coverage reports on my Groovy and Grails code don&#8217;t show the branch coverage that I expect they should.  I noticed that at some point in the past, Cobertura did show a correct branch report.  So I tried the grails code-coverage plugin with Cobertura version 1.8:

TADA!  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m trying to figure out why Cobertura coverage reports on my Groovy and Grails code <a href="/2008/01/27/branch-you-say-what-branch">don&#8217;t show the branch coverage that I expect they should</a>.  I noticed that at some point in the past, Cobertura did show a <a href="http://groovy.codehaus.org/Test+Coverage" onclick="javascript:pageTracker._trackPageview('/outbound/article/groovy.codehaus.org');" target="_blank">correct branch report</a>.  So I tried the grails code-coverage plugin with Cobertura <strong>version 1.8</strong>:</p>
<p><img src="http://piragua.com/wp-content/uploads/2008/01/100percentbranchcoverage.jpg" alt="100% Branch Coverage" /></p>
<p>TADA!  Now the reports are showing the coverage I expect. I know Cobertura (version 1.9) improved on the way it calculates branch coverage (see the news item from <span class="date">5 June 2007</span> on the <a href="http://cobertura.sourceforge.net/" onclick="javascript:pageTracker._trackPageview('/outbound/article/cobertura.sourceforge.net');" target="_blank">Cobertura</a> website) but for my purposes, Cobertura 1.8 gives me more of the information that I need.  I&#8217;m mostly concerned with finding code that isn&#8217;t tested at all, and that&#8217;s hard to do when almost every line of code is highlighted in red like version 1.9 was doing:</p>
<p><a href="http://piragua.com/wp-content/uploads/2008/01/branchCoverageController.jpg"  title="Branch Coverage on StateController"><img src="http://piragua.com/wp-content/uploads/2008/01/branchcoveragecontroller.thumbnail.jpg" alt="Branch Coverage on StateController" /></a></p>
<p>So for now I&#8217;ve updated the Grails <a href="http://plugins.grails.org/grails-code-coverage/trunk/grails-code-coverage-0.4.1.zip" onclick="javascript:pageTracker._trackPageview('/outbound/article/plugins.grails.org');">code-coverage plugin</a> to utilize Cobertura 1.8.  I can live without the new features that 1.9 offers and in the meantime I&#8217;ll work with the cobertura-devel folks to see if there&#8217;s something that we can improve for a future release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piragua.com/2008/01/31/accurate-branch-reports-with-grails-and-cobertura-_18_/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
