<?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>Nicholas Hagen</title>
	<atom:link href="http://www.znetdevelopment.com/blogs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.znetdevelopment.com/blogs</link>
	<description>Tidbits and blogs from Nicholas Hagen related to software, web design, and usability</description>
	<lastBuildDate>Mon, 07 May 2012 13:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Weekly Twitter Updates for 2012-05-07</title>
		<link>http://www.znetdevelopment.com/blogs/2012/05/07/weekly-twitter-updates-for-2012-05-07/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/05/07/weekly-twitter-updates-for-2012-05-07/#comments</comments>
		<pubDate>Mon, 07 May 2012 13:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2012/05/07/weekly-twitter-updates-for-2012-05-07/</guid>
		<description><![CDATA[Am I the only one who feels that #MVC based libraries in #Javascript or #nodejs are hacky to an extent due to the syntax and language? # Agree -&#62; RT @ForbesTech: Consumer Reports thinks that lots of Facebook users are idiots, notes @kashhill. http://t.co/LIxOYQk0 # Writing bytecode is quite exacerbating at times but equally rewarding. [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>Am I the only one who feels that #<a href="http://search.twitter.com/search?q=%23MVC" class="aktt_hashtag">MVC</a> based libraries in #<a href="http://search.twitter.com/search?q=%23Javascript" class="aktt_hashtag">Javascript</a> or #<a href="http://search.twitter.com/search?q=%23nodejs" class="aktt_hashtag">nodejs</a> are hacky to an extent due to the syntax and language? <a href="http://twitter.com/nicholas_hagen/statuses/198746139636404224" class="aktt_tweet_time">#</a></li>
<li>Agree -&gt; RT @<a href="http://twitter.com/ForbesTech" class="aktt_username">ForbesTech</a>: Consumer Reports thinks that lots of Facebook users are idiots, notes @<a href="http://twitter.com/kashhill" class="aktt_username">kashhill</a>. <a href="http://t.co/LIxOYQk0" rel="nofollow">http://t.co/LIxOYQk0</a> <a href="http://twitter.com/nicholas_hagen/statuses/198553504602783746" class="aktt_tweet_time">#</a></li>
<li>Writing bytecode is quite exacerbating at times but equally rewarding. Debugging is even worse. <a href="http://twitter.com/nicholas_hagen/statuses/197809428588797952" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/CedricChampeau" class="aktt_username">CedricChampeau</a>: Believe me, working with generics type checking isn&#039;t fun. &#8212; believe me, I know exactly what you mean <a href="http://twitter.com/nicholas_hagen/statuses/196959966115008513" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/05/07/weekly-twitter-updates-for-2012-05-07/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Twitter Updates for 2012-04-30</title>
		<link>http://www.znetdevelopment.com/blogs/2012/04/30/weekly-twitter-updates-for-2012-04-30/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/04/30/weekly-twitter-updates-for-2012-04-30/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2012/04/30/weekly-twitter-updates-for-2012-04-30/</guid>
		<description><![CDATA[@jaxzin I think you&#039;re right. The real question deals with an issue in #TeaTrove I need to resolve. # @jaxzin More of compare T to T (ie: Integer to Integer) but where I don&#039;t know the data type. I see the error prone but a num is a num IMO # Does anyone know why [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>@<a href="http://twitter.com/jaxzin" class="aktt_username">jaxzin</a> I think you&#039;re right. The real question deals with an issue in #<a href="http://search.twitter.com/search?q=%23TeaTrove" class="aktt_hashtag">TeaTrove</a> I need to resolve. <a href="http://twitter.com/nicholas_hagen/statuses/196242459578216448" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/jaxzin" class="aktt_username">jaxzin</a> More of compare T to T (ie: Integer to Integer) but where I don&#039;t know the data type. I see the error prone but a num is a num IMO <a href="http://twitter.com/nicholas_hagen/statuses/196235883119259648" class="aktt_tweet_time">#</a></li>
<li>Does anyone know why Number in #<a href="http://search.twitter.com/search?q=%23Java" class="aktt_hashtag">Java</a> is not Comparable even though all of its subclasses (Integer, Long, etc) are? Seems like it should. <a href="http://twitter.com/nicholas_hagen/statuses/196209939474169857" class="aktt_tweet_time">#</a></li>
<li>thanks @<a href="http://twitter.com/github" class="aktt_username">github</a> for the sweet update to easily create a new repo with a .gitignore file pre-created.  #<a href="http://search.twitter.com/search?q=%23simplicity" class="aktt_hashtag">simplicity</a> #github <a href="http://twitter.com/nicholas_hagen/statuses/195215446461521920" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/path" class="aktt_username">path</a> I use Path as my sole network to share pics 2 my close friends. Biggest issue is lack of a webui 4 non-smart phones. Keep up good work <a href="http://twitter.com/nicholas_hagen/statuses/194827742754254848" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/pledbrook" class="aktt_username">pledbrook</a> I logged into beta site via Twitter and created new acct which worked then auto-redirected to /admin/shiroOAuth/index which 404&#039;d <a href="http://twitter.com/nicholas_hagen/statuses/194826018119360512" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/04/30/weekly-twitter-updates-for-2012-04-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Twitter Updates for 2012-04-16</title>
		<link>http://www.znetdevelopment.com/blogs/2012/04/16/weekly-twitter-updates-for-2012-04-16/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/04/16/weekly-twitter-updates-for-2012-04-16/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2012/04/16/weekly-twitter-updates-for-2012-04-16/</guid>
		<description><![CDATA[As much as I dislike #MS I give them props for their culture shift..dissin&#039; #IE6 &#38; cntdown, focus on web tech/stds, open source subsidiary # Completely agree and all in -&#62; RT @mashable: Netflix&#039;s Unlimited Employee Vacation Policy; Why It Works &#8211; http://t.co/kTlL7WEn # RT @ChromiumDev innerHTML is now 240% faster in WebKit. And 6 [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>As much as I dislike #<a href="http://search.twitter.com/search?q=%23MS" class="aktt_hashtag">MS</a>  I give them props for their culture shift..dissin&#039; #<a href="http://search.twitter.com/search?q=%23IE6" class="aktt_hashtag">IE6</a> &amp; cntdown, focus on web tech/stds, open source subsidiary <a href="http://twitter.com/nicholas_hagen/statuses/190918036230901760" class="aktt_tweet_time">#</a></li>
<li>Completely agree and all in -&gt; RT @<a href="http://twitter.com/mashable" class="aktt_username">mashable</a>: Netflix&#039;s Unlimited Employee Vacation Policy; Why It Works &#8211; <a href="http://t.co/kTlL7WEn" rel="nofollow">http://t.co/kTlL7WEn</a> <a href="http://twitter.com/nicholas_hagen/statuses/190915234024796160" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/ChromiumDev" class="aktt_username">ChromiumDev</a> innerHTML is now 240% faster in WebKit. And 6 more huge DOM perf gains: <a href="http://t.co/ThxlrItM…" rel="nofollow">http://t.co/ThxlrItM…</a> <a href="http://twitter.com/nicholas_hagen/statuses/190232157552250881" class="aktt_tweet_time">#</a></li>
<li>Great post on #<a href="http://search.twitter.com/search?q=%23NodeJS" class="aktt_hashtag">NodeJS</a> by @<a href="http://twitter.com/brixen" class="aktt_username">brixen</a> and really understanding lang selection. Completely agree and worth the read <a href="http://t.co/CWNKPPnj" rel="nofollow">http://t.co/CWNKPPnj</a> <a href="http://twitter.com/nicholas_hagen/statuses/190036169420062720" class="aktt_tweet_time">#</a></li>
<li>Good post on Grails Best Practices: <a href="http://t.co/mOPuDOi8" rel="nofollow">http://t.co/mOPuDOi8</a> <a href="http://twitter.com/nicholas_hagen/statuses/189684200998313984" class="aktt_tweet_time">#</a></li>
<li>Anyone know if a rooted #<a href="http://search.twitter.com/search?q=%23Kindle" class="aktt_hashtag">Kindle</a> #Fire with Android Market can install and run the #<a href="http://search.twitter.com/search?q=%23Path" class="aktt_hashtag">Path</a> social app without issue? RT or reply if you know. <a href="http://twitter.com/nicholas_hagen/statuses/189561699043508224" class="aktt_tweet_time">#</a></li>
<li>Never used #<a href="http://search.twitter.com/search?q=%23Instagram" class="aktt_hashtag">Instagram</a> really, now I definitely never will. #<a href="http://search.twitter.com/search?q=%23AvoidFacebook" class="aktt_hashtag">AvoidFacebook</a> <a href="http://twitter.com/nicholas_hagen/statuses/189466976505176064" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/04/16/weekly-twitter-updates-for-2012-04-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Grails Dependency Fetching</title>
		<link>http://www.znetdevelopment.com/blogs/2012/04/13/understanding-grails-dependency-fetching/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/04/13/understanding-grails-dependency-fetching/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 21:22:46 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Dependency Management]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Ivy]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Nexus]]></category>
		<category><![CDATA[Repositories]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=559</guid>
		<description><![CDATA[If you have ever built or looked at a Grails project, you will notice that within the BuildConfig.groovy file there is a section called repositories that specifies all of the various repositories to pull in resources from. Grails is not built on any one type of repository system, instead it supports almost all of them. [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever built or looked at a Grails project, you will notice that within the <code>BuildConfig.groovy</code> file there is a section called <code>repositories</code> that specifies all of the various repositories to pull in resources from.  Grails is not built on any one type of repository system, instead it supports almost all of them.  It does this through Ivy so that it can support Maven repositories, Grails repositories, standard HTTP repositories, etc.  The problem with that, though, is that Grails via Ivy has to be pretty simplistic about how it achieves its lookups of dependencies.  At the simplest of levels this means that it purely queries each repository for a given resource.  To worsen the problem, the resources are usually specified in the GAV (group:artifact:version) pattern.  Those resources could be ZIP files, JAR files, POM files, etc.  Now, Ivy has to request each possible combination of allowed extensions to each repository until it finds a valid match.  If you have a project that depends on several libraries, this could result in minutes to hours of download time the first time a project is built.  Subsequent times will be fast as the resources are cached locally.  I still personally hate having to wait forever for an initial build to run.  So, how do you attempt to fix this in your project?<br />
<span id="more-559"></span><br />
The answer is to make sure you order your repositories in an order that makes sense to ensure that the repositories most of your resources will come from are attempted first.  Typically, the repositories are just nonchalantly thrown in any order and the result is long build times.  Even worse, transitive dependencies could bring in their own repository configuration multiplying the number of requests to make per dependency.  This is controlled by the <code>inherits true</code> statement, which is the default.  So, what should the order be?  It&#8217;s really up to you to decide.  The first rule is to always include any local repository (maven local, grails home, etc) first so that those dependencies resolve quickly and non-matches fail quickly.  The latter part is the key since you spend multiple requests to a repository for each dependency, which is costly for remote networks on the Internet.  If you work at a company that has a central Maven repository, like Nexus, then I would suggest putting that next as it will resolve your own Maven libraries as well proxy Maven central and any other Maven repository.  Plus, if you end up using many internal libraries, you will definitely want to utilize that repository first, especially since the request time and latency will be considerably less being in house rather than on the Internet.</p>
<p>Here are my recommended order of repositories:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// use Grails home first as it is local and quick and resolves all the standard Grails libraries quickly</span>
grailsHome<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// use maven home next if, and only if, you use maven so that your local dependencies are found quickly</span>
mavenLocal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// use your companies' Nexus repository that also proxies maven central and other repos</span>
<span style="color: #808080; font-style: italic;">// if you do not use maven, then do not use this or include it much later in the process</span>
<span style="color: #808080; font-style: italic;">// this only has value this high in the order if several of your dependencies use maven</span>
<span style="color: #808080; font-style: italic;">// or if the repository is in house on the same network</span>
mavenRepo <span style="color: #ff0000;">&quot;http://maven.company.org/...&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// use grails plugins next as it will resolve all the other plugins you use</span>
<span style="color: #808080; font-style: italic;">// if you use more plugins than you do libraries, then reference grails plugins first</span>
<span style="color: #808080; font-style: italic;">// before any maven repository</span>
grailsPlugins<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
grailsCentral<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// use maven central as a last step...again, only include this if you use maven libraries</span>
<span style="color: #808080; font-style: italic;">// also, do NOT use this if your in house Maven/Nexus repo proxies maven central</span>
mavenCentral<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// include any other maven repository not included in mavenCentral or your Nexus configuration</span>
<span style="color: #808080; font-style: italic;">// these are always one-offs typically so they should be last</span>
mavenRepo <span style="color: #ff0000;">&quot;http://company.org/maven/...&quot;</span></pre></div></div>

<p>The most important part is to <em><strong>only</strong></em> include the repositories you know you need. For example, if you have a company Nexus repository that proxies maven central, then only include one or the other, not both.  These rules are not meant in any way to be a firm stake, but something to give you context so you put thought into the ordering and how your environment, code, dependencies, and plugins work together.  After all, development time is precious.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/04/13/understanding-grails-dependency-fetching/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Java Bean Introspector and Covariant/Generic Returns</title>
		<link>http://www.znetdevelopment.com/blogs/2012/04/11/java-bean-introspector-and-covariantgeneric-returns/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/04/11/java-bean-introspector-and-covariantgeneric-returns/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 15:20:46 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Beans]]></category>
		<category><![CDATA[Bridge Methods]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Covariant]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[Introspector]]></category>
		<category><![CDATA[Property]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=553</guid>
		<description><![CDATA[Unfortunately, there is a rather unsettling bug in the JDK in the java.beans package for Introspector when handling bridge methods. For those unfamiliar with that term, JDK 5 created a new modifier called bridge that is only set by the compiler (ie: there is no actual keyword for it in the language that you can [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately, there is a rather unsettling bug in the JDK in the java.beans package for Introspector when handling bridge methods.  For those unfamiliar with that term, JDK 5 created a new modifier called bridge that is only set by the compiler (ie: there is no actual keyword for it in the language that you can use).  Bridge methods came along because of the new covariant returns and generics. For example, consider the following two classes<span id="more-553"></span>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Base <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Number</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Int <span style="color: #000000; font-weight: bold;">extends</span> Base <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Java allows you to override the return type of subclasses as long as the overridden type is compatible.  Behind the scenes, the compiler creates two methods in the actual <code>Int</code> class:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><span style="color: #003399;">Integer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">volatile</span> bridge getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><span style="color: #003399;">Number</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first method is the overridden return type and the actual method that is invoked.  The second method is a bridge method created by the compiler.  The bridge method purely invokes the first method but returns the value cast as a Number.  This has to occur since dependent classes that depend on the <code>Base</code> class can receive the expected <code>Number</code> return type whereas classes depending on <code>Int</code> directly can have the return type as an <code>Integer</code>.</p>
<p>Generics has the same problem with using the typed variable as the return value:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Base<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Number<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> T getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Int <span style="color: #000000; font-weight: bold;">extends</span> Base<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This again results in two methods for the <code>getValue</code> method.</p>
<p>The reason I mention this is that if you were to invoke <code>java.beans.Introspector.getBeanInfo(Int.class)</code> and then lookup the property for the <code>value</code> property, the property type and read method would be the bridge methods on some systems.  It is actually random since there is no defined ordered of methods in the class file format, so whichever appears first is the one that is selected.  On some machines that may be the <code>Integer</code>-based method, while on others it will be the bridge method.  In my opinion this is a huge gaping issue as several libraries depend on the underlying <code>java.beans</code> framework including Commons Beanutils.  They all exhibit similar issues as they all rely on the JDK.</p>
<p>This is actually worse than just the return types.  For example, if you have or use a library built around iterating the properties and then checking the read method for annotations, you may get the wrong method.  If the bridge method is returned it will not have any annotations on it.  Instead you would need to get the proper method to read the annotations.  This can cause unexpected issues that would be fairly hard to diagnose and debug.</p>
<p>Hopefully this will be resolved in JDK 7.  Until then, I have to fix my local code to hack the introspection library to walk each property, check if the read method is a bridge method and if so, lookup the actual method.  Here is a quick example on how to do that:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lookup bean info for given class</span>
<span style="color: #003399;">BeanInfo</span> info <span style="color: #339933;">=</span> <span style="color: #003399;">Introspector</span>.<span style="color: #006633;">getBeanInfo</span><span style="color: #009900;">&#40;</span>clazz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>info <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// get list of descriptors and iterate to validate each property</span>
    <span style="color: #003399;">PropertyDescriptor</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> descriptors <span style="color: #339933;">=</span> info.<span style="color: #006633;">getPropertyDescriptors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> descriptors.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">PropertyDescriptor</span> descriptor <span style="color: #339933;">=</span> descriptors <span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// check if read method is bridge and lookup real method</span>
        <span style="color: #003399;">Method</span> readMethod <span style="color: #339933;">=</span> descriptor .<span style="color: #006633;">getReadMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>readMethod <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> readMethod.<span style="color: #006633;">isBridge</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Method</span> method <span style="color: #339933;">=</span> clazz.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span>
                readMethod.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, readMethod.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// if method found, update read method</span>
            <span style="color: #666666; font-style: italic;">// which also updates property type</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>method <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                descriptor.<span style="color: #006633;">setReadMethod</span><span style="color: #009900;">&#40;</span>method<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// TODO: lookup write method with same type in case the write</span>
                <span style="color: #666666; font-style: italic;">// method is the bridge method</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// return array of found descriptors</span>
    <span style="color: #000000; font-weight: bold;">return</span> descriptors<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You would most likely want to perform similar logic on the write methods as write methods may also have bridge methods when dealing with generics. In this case, I would suggest looking up a <code>setXyz</code> method where the singular parameter type is the same as the return type from the newly found read method.  If the method is found, replace the existing write method with that method.</p>
<p>If you are wondering why <code>getMethod</code> returns only the non-bridged type whereas calling <code>getMethods</code> returns both methods in the array, the answer lies in the source code for that method in the <code>java.lang.Class</code> class.  The <code>getMethod</code> call eventually invokes <code>private static Method searchMethods</code>.  That search method has a condition on it that it loops through all methods that match the name but the array does not terminate early upon first match.  Instead, it keeps searching and if another matching method is found, then it uses the one with the more precise return type (ie: covariant returns).  Since covariant returns must always be subclasses of the base, the method just finds the return type with the lowest subclass, which should be the non-bridge method.</p>
<p>For more information, see the following JDK bugs on the topic:</p>
<ul>
<li><a href="http://bugs.sun.com/view_bug.do?bug_id=6788525">http://bugs.sun.com/view_bug.do?bug_id=6788525</a></li>
<li><a href="http://bugs.sun.com/view_bug.do?bug_id=6888164">http://bugs.sun.com/view_bug.do?bug_id=6888164</a></li>
<li><a href="http://bugs.sun.com/view_bug.do?bug_id=6707230">http://bugs.sun.com/view_bug.do?bug_id=6707230</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/04/11/java-bean-introspector-and-covariantgeneric-returns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing Modular Views with Grails</title>
		<link>http://www.znetdevelopment.com/blogs/2012/03/30/designing-modular-views-with-grails/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/03/30/designing-modular-views-with-grails/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 14:17:57 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[GSP]]></category>
		<category><![CDATA[Interceptor]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[Tag Library]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=548</guid>
		<description><![CDATA[One of the more common tasks in using a templating language like Grails is modular-based development. On a given page, you may have a common module used by several pages. For example, you may want a shopping cart on every page or have a set of social network widgets on various pages. Rather than duplicating [...]]]></description>
			<content:encoded><![CDATA[<p>One of the more common tasks in using a templating language like Grails is modular-based development.  On a given page, you may have a common module used by several pages.  For example, you may want a shopping cart on every page or have a set of social network widgets on various pages.  Rather than duplicating that effort across every page, you want to separate it out on its own so the functionality lives in one place.  Grails has several ways to do this, each with its own set of pros and cons.  This article will help walkthrough a variety of them and the use cases they were designed for.<br />
<span id="more-548"></span></p>
<p>The most simple way of creating modules is using sub-templates in Grails.  A sub-template in Grails is a GSP that starts with a leading underscore. This tells Grails that the template is a sub-template that does not live on its own but rather expects some other page or sub-template to invoke it.  Let&#8217;s say we want to include a login form on a variety of pages.  The login form is self-encompassing and can live on its own in terms of data models.  First, create a <code>_loginForm.gsp</code> file and include it in a new view directory called <code>login</code>.  You can actually place the sub<br />
template in any view directory, but for this exercise, we will assume it is in the <code>login</code> directory.</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;g:form controller=&quot;login&quot; action=&quot;login&quot;&gt;
    &lt;g:textField name=&quot;username&quot; /&gt;
    &lt;g:passwordField name=&quot;password&quot; /&gt;
&lt;/g:form&gt;</pre></div></div>

<p>Now to include that login form on any page, simply do <code>&lt;g:render template="/login/loginForm" /&gt;</code>  We have now separated out the common login form from the main page.  This method works great when the content is common and has no data associated with it.  What if the sub-template required some form of model or data, though? </p>
<p>Let&#8217;s look at a widget that displayed a &#8216;Similar Items&#8217; list on several pages, but the list of items was tied to the page displaying the widget.  For example, an electronics section may show other electronics, but a book section may show other books.  In this scenario, the sub-template does not know what the list of data should be, so it has to be provided.  This can again use sub-templates, but this time we can pass data into it.  Sub-templates can take a model as a map of variables to values such that the passed in variable names are available to be used within the sub-template.  Create a new sub-template in the <code>modules</code> view directory named <code>_similarItems.gsp</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;h3&gt;Similar Items : ${title}&lt;/h3&gt;
&lt;ul&gt;
&lt;g:each var=&quot;item&quot; in=&quot;${items}&quot;&gt;
    &lt;li&gt;${item}&lt;/li&gt;
&lt;/g:each&gt;
&lt;/ul&gt;</pre></div></div>

<p>This sub-template expects a &#8216;title&#8217; and list of &#8216;items&#8217;. We can now have various pages call this sub-template and provide the required model:</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;g:render template=&quot;/modules/similarItems&quot; 
          model=&quot;[title:'Books', items:[ 'Groovy in Action', 'Grails in Action' ]]&quot; /&gt;</pre></div></div>

<p>Any other page can easily include that same data but changing the model as need be.  You may even have the controller look up the related items from the database based on the active content being shown by the controller and then pass that data as the model of the controller so the view template can pass it to the sub-template model.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestController <span style="color: #009900;">&#123;</span>
    ItemsService itemsService
&nbsp;
    def index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        def section <span style="color: #339933;">=</span> params.<span style="color: #006633;">section</span> <span style="color: #339933;">?:</span> <span style="color: #0000ff;">'home'</span>
        def items <span style="color: #339933;">=</span> itemsService.<span style="color: #006633;">getItems</span><span style="color: #009900;">&#40;</span>section<span style="color: #009900;">&#41;</span>
        def related <span style="color: #339933;">=</span> itemsService.<span style="color: #006633;">getRelated</span><span style="color: #009900;">&#40;</span>section<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#91;</span> section <span style="color: #339933;">:</span> section, items <span style="color: #339933;">:</span> items, related <span style="color: #339933;">:</span> related <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;h1&gt;${section}&lt;/h1&gt;
&lt;ul&gt;
&lt;g:each var=&quot;item&quot; in=&quot;${items}&quot;&gt;
    &lt;li&gt;${item}&lt;/li&gt;
&lt;/g:each&gt;
&lt;/ul&gt;
&nbsp;
&lt;g:render template=&quot;/modules/similarItems&quot;
          model=&quot;[title : section, items : related ]&quot; /&gt;</pre></div></div>

<p>Another method to do the same thing is using the <code>tmpl</code> namespace in Grails.</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;tmpl:similarItems title=&quot;${section}&quot; items=&quot;${related}&quot; /&gt;</pre></div></div>

<p>This example is slighly easier to read as the model is provided as attributes to the tag instead of an inline map/array to the tag.  The use of one or the either is entirely a choice as long as the decision is consistent to avoid confusion. For more information on the render tag, see <a href="http://grails.org/doc/2.0.x/ref/Tags/render.html">http://grails.org/doc/2.0.x/ref/Tags/render.html</a>.</p>
<p>These are the most common use cases.  What if we do not need to pass any data to the sub-template, but the sub-template needs to acquire data as part of its visual rendering.  For example, you may want to show a shopping cart on every page.  The shopping cart will always have the same data regardless which page calls it, but it needs to retrieve its data from the <code>ShoppingCartService</code>.  There are a few different ways to do this, again with pros and cons in each scenario.</p>
<p>Let&#8217;s start again with the easy way using sub-templates. Grails contains a <code>g:set</code> tag that allows you to set scoped variables (typically page scoped) based on some expression.  The expression can then lookup services to retrieve the necessary data.  Let&#8217;s create a <code>_shoppingCart.gsp</code> in the <code>modules</code> directory.</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;g:set var=&quot;shoppingCart&quot; value=&quot;${model.shoppingCart}&quot; /&gt;
&lt;h3&gt;Shopping Cart&lt;/h3&gt;
&lt;ul&gt;
    &lt;g:each var=&quot;item&quot; value=&quot;${shoppingCart.items}&quot;&gt;
        &lt;li&gt;${item.name}&lt;/li&gt;
    &lt;/e:each&gt;
&lt;/ul&gt;</pre></div></div>

<p>This is fairly simple and a page can easily include without having to pass or look up any model data. However, this requires every page controller using this sub-template to define the <code>model.shoppingCart</code> bean as part of its model.  I will show how to do that easily next.  A feature request for a future version of Grails is to allow the <code>g:set</code> tag to include a <code>bean</code> attribute on the <code>set</code> tag to allow easier access to beans such as services. This would allow sub-templates to be independent of tag libraries and controllers.</p>
<p><code>&lt;g:set var="shoppingCartService" bean="shoppingCartService" /&gt;</code></p>
<p>Unfortunately, that is not yet possible howerver.</p>
<p>As a simple example, this was pretty straightforward.  However, what if you need to do a bunch of business logic or manipulation of the data.  In these use cases, you would not want to purely use a sub-template as you want to avoid mixing business logic from presentation (ie: the whole principle of MVC).  I&#8217;ll skip the more standard approach first and jump to a non-traditional example for the sake of demonstrating alternative options as well as explaining how to include a common model across several pages (such as the shopping cart example above).</p>
<p>The non-traditional way to solve this is to have the controllers do the business logic and then include the resulting data in the model.  Then, the sub-template will have access to the associated data.  However, if you did this in every controller, you would end up with duplicated code.  So, how do you allow any controller to perform the business logic and include it in the resulting model?  The answer lies in inheritance and listeners in Grails.  For example, create an abstract Groovy class <code>BaseController</code> and then ensure each specific controller extends this base controller.  The base controller can now include an interceptor that will intercept any action in any sub-class allowing modifications to the resulting model.  This modification could be the result of business logic performed.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BaseController <span style="color: #009900;">&#123;</span>
    ShoppingCartService shoppingCartService
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span> afterInterceptor <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> model <span style="color: #339933;">-&gt;</span>
        model.<span style="color: #006633;">shoppingCart</span> <span style="color: #339933;">=</span> shoppingCartService.<span style="color: #006633;">getShoppingCart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ProductController <span style="color: #000000; font-weight: bold;">extends</span> BaseController <span style="color: #009900;">&#123;</span>
    def productService
&nbsp;
    def index<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> productId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        def product <span style="color: #339933;">=</span> productService.<span style="color: #006633;">getProduct</span><span style="color: #009900;">&#40;</span>productId<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">'product'</span> <span style="color: #339933;">:</span> product <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice that the product controller has no notion of the business logic and associatd data for the shopping cart, yet the model that is given to the page will include the &#8216;shoppingCart&#8217; bean.  This clearly separates the concerns but still allows the base controller to inject the data into the model.  Because the data is in the model, GSPs can now pass the data to the sub-templates:</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">Cart:
&lt;g:render template=&quot;/moules/cart&quot; model=&quot;[ cart : shoppingCart ]&quot; /&gt;</pre></div></div>

<p>You still use the power of sub-templates and separation of concerns.  However, the downfall is that every controller using that sub-template needs to extend the base controller.  If the base controller is not implemented, then the model data will be unavailable.</p>
<p>The more traditional way to solving this is through tag libraries.  Tag libraries are powerful, very modular, and written in standard Groovy.  Tag libraries are similar to tag libraries in JSP or JSF, but without all the annoying headaches of configuration.  You simply create a new tag library class and it all gets autowired by Grails.  Tag libraries are great for performing common logic and outputting common HTML.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserTagLibrary <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> namespace <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user'</span>
&nbsp;
    UserService userService
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This displays a welcome message to the logged in user.
     *
     * @attr message Message to display to the user, defaults to 'Welcome'
     */</span>
    def profile <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> attrs, body <span style="color: #339933;">-&gt;</span>
        def user <span style="color: #339933;">=</span> userService.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span>session.<span style="color: #006633;">user</span><span style="color: #009900;">&#41;</span>
        def message <span style="color: #339933;">=</span> attrs.<span style="color: #006633;">message</span> <span style="color: #339933;">?:</span> <span style="color: #0000ff;">'Welcome'</span><span style="color: #339933;">;</span>
        out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;${message} ${user.firstName} ${user.lastName}&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Tag libraries all end with the common suffix <code>TagLibrary</code> by convention.  The first thing to note is the static <code>namespace</code> constant.  This tells Grails what prefix to use in GSPs.  By default, tag libraries default to the global Grails namespace <code>g</code>.  Providing the <code>namespace</code> constant overrides that value.  You will also note that tag libraries can automatically inject other services and beans.  Finally, you define closures as the available tags.  The closures take one argument as the list of key/value pair attributes and one argument as the optional body of the tag.  You then define the logic within the closure and use the predefined <code>out</code> variable to send content to the page.  In this example, we could write <code>&lt;user:profile message="Hello" /&gt;</code> on any page and have it generate &#8220;Welcome Nicholas Hagen&#8221; for example.</p>
<p>The problem, however, is that we are going back to the good ol&#8217; days of pure Servlet programming where we are generating HTML and concatenating strings together.  The Groovy Strings simplifies the concatenation, but we are still outputting HTML and having to worry about escaping characters, etc.  There is a reason why JSP was created to remove the annoyance of writing HTML inline with your logic.  So, what can we do to avoid this and get the power of GSP&#8217;s for HTML output and the power of tag libraries for performing business logic and generating models?</p>
<p>In typical Grails fashion, the answer is quite simple yet again.  Tag libraries, along with controllers, can actually invoke other tag libraries.  This means that the tag library can act as the business logic processor and invoke the <code>render</code> tag to pass the resulting data model to a GSP to actually render the contents.  This is exactly what we were doing earlier, only this time the tag library is invoking render rather than the page.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ProductTagLibrary <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> namespace <span style="color: #339933;">=</span> <span style="color: #0000ff;">'p'</span>
&nbsp;
    ProductService productService
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Generate a list of similar items based on a given product id.
     *
     * @attr productId REQUIRED The id of the product being displayed
     */</span>
    def simlarItems <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> attrs, body <span style="color: #339933;">-&gt;</span>
        <span style="color: #666666; font-style: italic;">// validate the data</span>
        def productId <span style="color: #339933;">=</span> attrs.<span style="color: #006633;">productId</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>productId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'productId'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// lookup the associated product</span>
        def product <span style="color: #339933;">=</span> productService.<span style="color: #006633;">getProduct</span><span style="color: #009900;">&#40;</span>productId<span style="color: #009900;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>product<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;No product available&quot;</span>
            <span style="color: #000000; font-weight: bold;">return</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// get the name of the product section</span>
        def section <span style="color: #339933;">=</span> product.<span style="color: #006633;">section</span>.<span style="color: #006633;">name</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// lookup similar items and process</span>
        def products <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
        def similar <span style="color: #339933;">=</span> productService.<span style="color: #006633;">getSimilarItems</span><span style="color: #009900;">&#40;</span>product<span style="color: #009900;">&#41;</span>
        similar.<span style="color: #006633;">each</span> <span style="color: #009900;">&#123;</span> it <span style="color: #339933;">-&gt;</span>
            <span style="color: #666666; font-style: italic;">// do stuff and logic</span>
            products <span style="color: #339933;">&lt;&lt;</span> it
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// render the similar items template passing the model</span>
        g.<span style="color: #006633;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span> template<span style="color: #339933;">:</span><span style="color: #0000ff;">'/modules/similarItems'</span>, model<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span> title<span style="color: #339933;">:</span> section, items<span style="color: #339933;">:</span>products <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This example basically looks up a given product, finds similar products to it, performs some level of business logic against those products and then calls the sub-template to actually render the data.  Instead of having pages invoke the similar items sub-template, the pages simply invoke <code>&lt;p:similarItems productId="${params.productId}" /&gt;</code>.  This creates a clear separation in the system. The page only knows about tags it can invoke and does not have to carry about where those tags live, what they do, etc.  The tag library only has to perform business logic and setup the data model without worrying about HTML to invoke.  The sub-template only has to worry about the HTML to output and not how to setup data.</p>
<p>One final thing I will note is there is an active <a href="http://grails.org/plugin/gsp-taglib">GSP tags plugin</a> that allows you to define tag libraries purely as a GSP where the only thing the tag library is doing is outputting HTML.  This can come in very handy as well. However, if you have complex business logic to perform, separating the logic into a tag library and the content into a GSP is still the better option typically.</p>
<p>There are probably several other useful approaches other than these and feel free to drop a comment on your experiences.  Ultimately, it comes down to a use case decision and strategy decsion.  Here are some simple rules that I tend to follow when making decisions:</p>
<ol>
<li>Use sub-templates for common code with no business logic (purely HTML output driven by an optional model)</li>
<li>Use basic tag libraries for utility functions or very short one line HTML snippets</li>
<li>Use tag libraries along with sub-templates for complex business logic and complex HTML snippets</li>
</ol>
<p>Hopefully this posts helpd you understand the various ways of handling modular programming within Grails.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/03/30/designing-modular-views-with-grails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Weekly Twitter Updates for 2012-03-26</title>
		<link>http://www.znetdevelopment.com/blogs/2012/03/26/weekly-twitter-updates-for-2012-03-26/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/03/26/weekly-twitter-updates-for-2012-03-26/#comments</comments>
		<pubDate>Mon, 26 Mar 2012 13:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2012/03/26/weekly-twitter-updates-for-2012-03-26/</guid>
		<description><![CDATA[I don&#039;t understand how you can trademark common nouns like &#34;face&#34; and &#34;book&#34;. Doesn&#039;t that imply that &#34;facetime&#34; is in violation? # PSA: Enable IDE warnings for #autoboxing in @java and use autoboxing with care. This way you avoid accidental bugs and headaches like NPE # My task this morning and this week: moving my [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>I don&#039;t understand how you can trademark common nouns like &quot;face&quot; and &quot;book&quot;. Doesn&#039;t that imply that &quot;facetime&quot; is in violation? <a href="http://twitter.com/nicholas_hagen/statuses/183378402856804353" class="aktt_tweet_time">#</a></li>
<li>PSA: Enable IDE warnings for #<a href="http://search.twitter.com/search?q=%23autoboxing" class="aktt_hashtag">autoboxing</a> in @<a href="http://twitter.com/java" class="aktt_username">java</a> and use autoboxing with care. This way you avoid accidental bugs and headaches like NPE <a href="http://twitter.com/nicholas_hagen/statuses/183159870034427904" class="aktt_tweet_time">#</a></li>
<li>My task this morning and this week: moving my blog and site to #<a href="http://search.twitter.com/search?q=%23Linode" class="aktt_hashtag">Linode</a> for better performance <a href="http://t.co/m363LgYK" rel="nofollow">http://t.co/m363LgYK</a> <a href="http://twitter.com/nicholas_hagen/statuses/182793964347334656" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/03/26/weekly-twitter-updates-for-2012-03-26/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Generics in Collections</title>
		<link>http://www.znetdevelopment.com/blogs/2012/03/22/understanding-generics-in-collections/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/03/22/understanding-generics-in-collections/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 11:34:20 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[ParameterizedType]]></category>
		<category><![CDATA[Semantics]]></category>
		<category><![CDATA[Wildcard]]></category>
		<category><![CDATA[WildcardType]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=544</guid>
		<description><![CDATA[Generics in Java is one of those features where almost everyone uses but very people, including myself, really understand. I had a conversation just today about understanding a use case of generics within collections and came to a realization of why generics were applied in a certain way. It is very important to not only [...]]]></description>
			<content:encoded><![CDATA[<p>Generics in Java is one of those features where almost everyone uses but very people, including myself, really understand. I had a conversation just today about understanding a use case of generics within collections and came to a realization of why generics were applied in a certain way.  It is very important to not only understand the base concept of generics (ie: <code>List<String> strings = new ArrayList<String>();</code>), but to also understand the subtle differences. Generics are very powerful after all. In particular, there are a few different ways to declare generics within collections and they all appear similar, but have very different meanings.  Understanding these subtle differences can help alleviate any misconception as to why your IDE or compiler throws an error or warning in a certain situation.</p>
<p><!-- more --></p>
<p>My conversation today revolved around the notion of generics with wildcards. Generics supports the notion of wildcards in a few different usecases:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>Number<span style="color: #339933;">&gt;</span> l <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// simple parameterized type</span>
List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Number<span style="color: #339933;">&gt;</span> l <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// wildcard with upper bounds</span>
List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">super</span> Integer<span style="color: #339933;">&gt;</span> l <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// wildcard with lower bounds</span>
List<span style="color: #339933;">&lt;?&gt;</span> l <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// wildcard with no bounds (bounds to Object)</span></pre></div></div>

<p>The simple parameterized type is self-explanatory and most popular.  The latter non-boundary-based wildcard is also pretty self explanatory and commonly used.  The wildcard with a lower bounds (<code>? super T</code>) is rarely used but has specific use cases, none of which I will dig into in this article.  However, I do encourage you to investigate what it means and why you might want to use it (hint: the most common use case is comparables such as <code>java.util.Collections.sort</code>). The upper bounds wildcard, especially as it pertains to collections, is what we are interested in today.</p>
<p>Take the following example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>Animal<span style="color: #339933;">&gt;</span> animals<span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals<span style="color: #339933;">;</span></pre></div></div>

<p>Those two declarations are very similar to each other, but there is a very keen difference.  The first case is saying the list will contain a possible mixture of any objects that are or extend from Animal.  In other words, you could have a list containing dogs and cats, since both are animals.  The second case is saying the list will contain a set of objects whose base extends from animal. That&#8217;s almost the same thing, but the difference is that the latter list has the possibility to only contain dogs or only contain cats. The first case is always open to containing a mixture.  It all boils down to developer intent.  The wildcard is used by a developer to basically say &#8220;I know I have a specific type of list, but I&#8217;m just not sure what that type might be at this moment&#8221;. It allows the developer to ensure that the list will only contain a given type.  The first case would allow the developer to put anything in that list.  If the intent is to ensure the list can only contain dogs, that would fail as you could put cats into it.</p>
<p>Let&#8217;s consider a use case.  Consider a factory class that returns a list of a given animal.  You may not know what type of animal you will get back, so you can&#8217;t type it as a specific animal.  However, you still want to ensure that the caller retrieving the list treats it as a specific type and not allowing them to add other animals to it.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AnimalFactory <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> getAnimals<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// return either List&lt;Dog&gt; or List&lt;Cat&gt; for example</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> getAnimals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dogs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        animals.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Cat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this fails</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This example fails because we attempt to put a cat into a wildcarded animal list.  However, if the declaration was simply <code>List<Animal></code>, then we could add a cat just fine.  The wildcard type says that the list is typed as something specific, but it&#8217;s exact value is not yet known.  Because of that reason, Java disallows you to add a cat to the list because that list may in fact be a list of dogs and that would be invalid.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span> dogs <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
dogs.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Cat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// invalid</span></pre></div></div>

<p>Let&#8217;s look at some more commonly misused examples.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// works</span>
List<span style="color: #339933;">&lt;</span>Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// fails</span></pre></div></div>

<p>The first example works, because <code>ArrayList<Dog></code> satisfies the wildcard.  A list of dogs is a specific type of a list of animals. The second case, however, fails because a list of dogs is not the same thing as a list of animals.  The reason is that you could add a cat to the latter list (since a cat is an aminal) and that would deem the list of dogs invalid (a cat is not a dog).  The first example you cannot add a cat or a dog, since Java does not know the exact type to allow.</p>
<p>So, how do you add to a list when it is typed as <code>? extends T</code>.  The simple answer is you don&#8217;t and I believe that is one of the rationales and use cases for declaring a list in that manner.  If we consider our factory example again, the use case for retrieving the list is most likely to be able to iterate and act upon it, not add or modify it.  In that scenario, the following code works just fine since you know the list contains animals, you are just not sure what type.  In other words, you can treat the items in the list as some form of animal generally, but you cannot change the list without knowing what the exact type is (in order to maintain the semantics of a specific type being in the list).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> AnimalFactory.<span style="color: #006633;">getAnimals</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Animal animal <span style="color: #339933;">:</span> animals<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    animal.<span style="color: #006633;">speak</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>But what if you really, really, really need to update the list.  The answer is just type cast it and away you go.  After all, types in Java are erased anyways (see my type erasure blog for more information).  You may get a Java warning though in doing so, but it&#8217;s just warning you that you are taking code into your your own hands and assuming responsibility (ie: possibly casting what at runtime is a list of cats into a list of dogs).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> AnimalFactory.<span style="color: #006633;">getAnimals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cats&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span> dogs <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> animals<span style="color: #339933;">;</span>
dogs.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Dog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Dog dog <span style="color: #339933;">:</span> dogs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// ack...class cast exception because the list was actually List&lt;Cat&gt;</span>
   dog.<span style="color: #006633;">bark</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you were using arrays, you could not do: <code>Dog[] dogs = (Dog[]) new Cats[] { new Cat(); }</code>.  However, that is essentially what you are saying above.  Since types are erased in Java and the list is just a list at runtime, Java cannot really enforce the check as an error and instead gives you a warning stating that you may be converting a list of cats into a list of dogs which would not be possible under the normal rules of the universe.</p>
<p>Let&#8217;s look at one final example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> process<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Animal<span style="color: #339933;">&gt;</span> animals<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do stuff</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Animal<span style="color: #339933;">&gt;</span> animals <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Dog<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    process<span style="color: #009900;">&#40;</span>animals<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// fails</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This example once again fails.  By now you hopefully understand why.  Even though you can define the dogs as <code>? extends Animal</code> and then declare it as <code>ArrayList<Dog></code>, you still cannot pass that list into a method that expects a certain type.of animals.  Even when the list is typed as <code>List<Animal</code>, you are still saying you have a list of some type of animal.  It may be a list of cats or it may be a list of dogs in this example.  The process method, however, is accepting a list that supports both cats and dogs or any other animal.  It is almost the same thing but the key difference is that the declaration is saying I have a specific type of animals whereas the method is saying I support all animals. If that does not convince you, put the pieces from earlier together.  Within the process method, we saw earlier we could do: <code>animals.add(new Cat())/code><br />
since cat is an animal.  However, we were not able to do the same when the type was <code>? extends Animal</code> because we were not guaranteed to have a known type that would be satisfactory to the actual list at runtime.  If that is true, then Java cannot allow you to pass in the animals variable to the method because you could add a cat or a dog or whatever to it.  </p>
<p>In other words, a List<Animal> is not necessarily a List<? extends Animal>. They could be the same, but one is more generic than the other.  After all, the following is valid: <code>List<? extends Animal> animals = new ArrayList<Animal></code> in which case it is the same as List<Animal> at runtime.  The keyword here being runtime.  The compiler only works at compile time and all it knows from the definition is that it is a specific type of "something" but what that something is is not known until runtime, so prevent any type of modification to the contents of that "something" that could alter the semantics of the actual runtime declaration.</p>
<p>Hopefully this helped to clarify any misunderstandings between generics in collections and helps you to better utilize the proper form when handling collections. The basic rules are these:</p>
<ul>
<li>
Use <code>? extends T</code> when you do not need modification of the contents and want to ensure a specific type is always being used. NOTE: this does not<br />
guarantee modification of the contents since you can always type cast (use an unmodifiable collection for that).
</li>
<li>
Use <code>T</code> when you are talking about a collection that can handle and contain any type of T and it does not matter if the list contains a dog and a cat<br />
for example.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/03/22/understanding-generics-in-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Twitter Updates for 2012-03-19</title>
		<link>http://www.znetdevelopment.com/blogs/2012/03/19/weekly-twitter-updates-for-2012-03-19/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/03/19/weekly-twitter-updates-for-2012-03-19/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 13:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2012/03/19/weekly-twitter-updates-for-2012-03-19/</guid>
		<description><![CDATA[GIt commands for working with multiple GitHub forks: http://t.co/BqlNBGrb # Analysts make a big deal out of iPhone/iPad share decreasing and Android increasing&#8230;does not matter when Apple makes 2-3x more per unit # @marcinos85 Thanks&#8230;.I&#039;m still getting things setup &#38; hope to update the README tomorrow w/ more info and setup the Issues in GitHub [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>GIt commands for working with multiple GitHub forks: <a href="http://t.co/BqlNBGrb" rel="nofollow">http://t.co/BqlNBGrb</a> <a href="http://twitter.com/nicholas_hagen/statuses/180110586829475841" class="aktt_tweet_time">#</a></li>
<li>Analysts make a big deal out of iPhone/iPad  share decreasing and Android increasing&#8230;does not matter when Apple makes 2-3x more per unit <a href="http://twitter.com/nicholas_hagen/statuses/179954601884258305" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/marcinos85" class="aktt_username">marcinos85</a> Thanks&#8230;.I&#039;m still getting things setup &amp; hope to update the README tomorrow w/ more info and setup the Issues in GitHub <a href="http://twitter.com/nicholas_hagen/statuses/179298445931192320" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/03/19/weekly-twitter-updates-for-2012-03-19/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Servlet Container Temporary Directory</title>
		<link>http://www.znetdevelopment.com/blogs/2012/03/14/accessing-servlet-container-temporary-directory/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/03/14/accessing-servlet-container-temporary-directory/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 21:19:22 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[Servlet Container]]></category>
		<category><![CDATA[TeaTrove]]></category>
		<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=540</guid>
		<description><![CDATA[As part of a recent project, I had a need to generate classes to a temporary directories. Currently, this was being done by a simple File-based path. However, that has two downfalls: the paths are tied to the implementation of the application server and files may be blocked in the application server. However, JSPs do [...]]]></description>
			<content:encoded><![CDATA[<p>As part of a recent project, I had a need to generate classes to a temporary directories. Currently, this was being done by a simple File-based path.  However, that has two downfalls: the paths are tied to the implementation of the application server and files may be blocked in the application server.  However, JSPs do this all the time by storing their resulting classes to the work or temporary directory in the application.  I had to search several variants of keywords to find my answer, but the <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#TEMPDIR">servlet spec</a> actually has the notion of a work directory for this type of work.  You access the directory through the <code>ServletContext.getAttribute</code> method.  In servlet spec 2.5 and below, the static constant TEMPDIR is not defined.  Instead, you use the constant <code>javax.servlet.context.tempdir</code>.  The returned value is of type <code>java.io.File</code> that you can use as the base directory.  For example, <span id="more-540"></span></p>
<p><script src="https://gist.github.com/2039581.js?file=gistfile1.java"></script></p>
<p>With this, the test file will be stored in the working directory of the deployed web application.  Note that files stored are temporary and may or may not be preserved across restarts.  The servlet container manages the actual files once the application is shutdown.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/03/14/accessing-servlet-container-temporary-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

