<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4368777317649012081</atom:id><lastBuildDate>Sun, 15 Jun 2025 06:29:08 +0000</lastBuildDate><category>migrated</category><category>mybatis</category><category>tomcat</category><category>mysql</category><category>eclipse</category><category>jsp</category><category>logback</category><category>log4j</category><category>servlets</category><category>android</category><category>angularjs</category><category>dao</category><category>el</category><category>java</category><category>javascript</category><category>tld</category><category>web applications</category><category>agile</category><category>css</category><category>funny</category><category>git</category><category>gui</category><category>i18n</category><category>interesting</category><category>jstl</category><category>junit</category><category>logging</category><category>opinions</category><category>pojo</category><category>rails</category><category>ruby</category><category>spring</category><category>struts</category><category>videos</category><category>wsh</category><title>The IdleWorx Blog</title><description>AngularJS, Python, Java, Tomcat, Servlets, JSP, Android, Ruby and other programming stuff ...</description><link>http://blog.idleworx.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>57</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-5938111996039499377</guid><pubDate>Thu, 22 Dec 2022 00:56:00 +0000</pubDate><atom:updated>2016-04-24T11:36:33.122-07:00</atom:updated><title>Welcome to the IdleWorx blog</title><description>This is the official blog of &lt;a href=&quot;http://www.idleworx.com/&quot; target=&quot;_blank&quot;&gt;idleworx.com&lt;/a&gt;.  A blog covering AngularJS, Python, Android, JSP, Servlets, Tomcat, JavaScript, Ruby and other web development stuff. </description><link>http://blog.idleworx.com/2000/01/welcome.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-7115305777496937483</guid><pubDate>Thu, 30 Oct 2014 00:38:00 +0000</pubDate><atom:updated>2017-03-10T19:54:41.912-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Creating a sortable table from an array of complex objects, with custom column ordering, using pure AngularJS</title><description>Read this on medium.com instead:&amp;nbsp;&lt;a href=&quot;https://medium.com/@idleworx/16af1d9edeae?source=tw-ab7a0a61509e-1414631999267&quot;&gt;https://medium.com/@idleworx/16af1d9edeae?source=tw-ab7a0a61509e-1414631999267&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In a recent project I came across a more complex scenario when needing to create a table (from an array of complex objects as the model)&lt;br /&gt;
&lt;br /&gt;
More specifically, I have a list of &lt;b&gt;items&lt;/b&gt; to render.&lt;br /&gt;
Each &lt;b&gt;item&lt;/b&gt; is an object which contains multiple &lt;b&gt;fields&lt;/b&gt;.&lt;br /&gt;
Each &lt;b&gt;field&lt;/b&gt; is an object that has &lt;i&gt;name, value&lt;/i&gt; and &lt;i&gt;order&lt;/i&gt; properties.&lt;br /&gt;
So for example one &lt;b&gt;item &lt;/b&gt;looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript; wrap-lines:false;&quot;&gt;{
    &quot;fields&quot;: {
      &quot;link&quot;: {
        &quot;description&quot;: &quot;Link&quot;,
        &quot;name&quot;: &quot;link&quot;,
        &quot;order&quot;: 1,        
        &quot;value&quot;: &quot;http://www.google.com&quot;
      },
      &quot;name&quot;: {
        &quot;description&quot;: &quot;Name&quot;,
        &quot;name&quot;: &quot;name&quot;,
        &quot;order&quot;: 2,        
        &quot;value&quot;: &quot;Google Homepage&quot;
      },
      &quot;notes&quot;: {
        &quot;description&quot;: &quot;Notes&quot;,
        &quot;name&quot;: &quot;notes&quot;,
        &quot;order&quot;: 4,        
        &quot;value&quot;: &quot;Notes about google&quot;
      },
      &quot;price&quot;: {
        &quot;description&quot;: &quot;Price&quot;,
        &quot;name&quot;: &quot;price&quot;,
        &quot;order&quot;: 3,        
        &quot;value&quot;: &quot;100&quot;
      }
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;The Problem (Requirements)&lt;/span&gt;&lt;/h2&gt;
What I need to do is to render a table from an array of &amp;nbsp;&lt;b&gt;items&lt;/b&gt;, so multiple items as the one above, in such a way that the field names become the columns &amp;nbsp;(using the order specified in the field.order value), and each column is sortable.&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can assume here that the ordering of all fields in each item is the same, and all items have the same fields. So each item is different only differ in the fields&#39; value property)&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To make this simpler to understand, using the relational table concept, think of the items as records, and the fields for each item as the columns (ordered columns at that).&lt;br /&gt;
&lt;br /&gt;
The final output would look like this given 3 items (with each column header clickable)&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-VLdCrj0o7us5BmL-ShkkcsxV9F77-sNOjn2qsri6jHEaiedt3CP__AJkOzP3Y5j18xK8XlVt0-YqdMRbOBxmv6lVyV5Mmb0jo4eosJXdN20ZMIb05x_UsTO7CqSh7il30LJ-HGcctqgP/s1600/angular_table.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;AngularJS Complex Table Example&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-VLdCrj0o7us5BmL-ShkkcsxV9F77-sNOjn2qsri6jHEaiedt3CP__AJkOzP3Y5j18xK8XlVt0-YqdMRbOBxmv6lVyV5Mmb0jo4eosJXdN20ZMIb05x_UsTO7CqSh7il30LJ-HGcctqgP/s1600/angular_table.png&quot; title=&quot;AngularJS Complex Table Example&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;clear: both;&quot;&gt;
So how would you render something like this?&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;The Solution&lt;/span&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;h3&gt;
1. Write a helper method for sorting an item&#39;s fields&lt;/h3&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
First I need a method that returns a sorted array of fields (that I will call from the partial)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;getFieldsSorted(item);&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript; wrap-lines:false;&quot;&gt;function getFieldsSorted(item){
  var fields = _.sortBy(item.fields,&#39;order&#39;); //using the awesome underscorejs library
  return fields;
};
&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;
When run, given the item&#39;s JSON defined before, this method will return a sorted array of fields, based on the field.order property, that looks like this. So for a single item, this method would return:&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript; wrap-lines:false;&quot;&gt;[
  {
    &quot;description&quot;: &quot;Link&quot;,
    &quot;name&quot;: &quot;link&quot;,
    &quot;order&quot;: 1,    
    &quot;value&quot;: &quot;http://www.google.com&quot;
  },
  {
    &quot;description&quot;: &quot;Name&quot;,
    &quot;name&quot;: &quot;name&quot;,
    &quot;order&quot;: 2,    
    &quot;value&quot;: &quot;Google Homepage&quot;
  },
  {
    &quot;description&quot;: &quot;Price&quot;,
    &quot;name&quot;: &quot;price&quot;,
    &quot;order&quot;: 3,    
    &quot;value&quot;: &quot;100&quot;
  },
  {
    &quot;description&quot;: &quot;Notes&quot;,
    &quot;name&quot;: &quot;notes&quot;,
    &quot;order&quot;: 4,    
    &quot;value&quot;: &quot;Notes about google&quot;
  }
]
&lt;/pre&gt;
&lt;div&gt;
Note here that unlike the unsorted item defined in the beginning, in which the fields were sorted: &lt;i&gt;Link, Name, Notes,Price, &lt;/i&gt;after the &lt;i&gt;getFieldsSorted(item)&lt;/i&gt; is called, the fields are now sorted as: &lt;i&gt;Link, Name, Price, Notes&lt;/i&gt; because that is how the field ordering is defined.&lt;/div&gt;
&lt;div&gt;
This requirement about ordering fields, is so because in my particular case the user will need to be able to customize the field ordering of the item&#39;s fields.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Now we&#39;ll use Angular&#39;s ng-repeat directive to generate a sortable table from an array of 3 items&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;h3&gt;
2. Render the table columns using the order of the fields&lt;/h3&gt;
&lt;br /&gt;
Since an item&#39;s fields are not in ordered by default according to the &lt;i&gt;field.order&lt;/i&gt; property, we&#39;ll make use of the &lt;i&gt;getFieldsSorted(item)&lt;/i&gt;&amp;nbsp;helper method defined before.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
First we&#39;ll use &lt;i&gt;ng-repeat&lt;/i&gt; to generate the table header with all the fields in order.&lt;br /&gt;
&lt;br /&gt;
Since all the fields are the same across all items (except for their value property), we&#39;ll just use the first item&#39;s fields to render the table column header.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;&amp;lt;table class=&quot;table table-striped&quot; ng-if=&quot;items.length &amp;gt; 0&quot;&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th ng-repeat=&quot;field in getFieldsSorted(items[0])&quot;&amp;gt;
            {{field.description}}            
        &amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;h3&gt;
3. Render the table columns using the order of the fields&lt;/h3&gt;
&lt;div&gt;
We&#39;ll use the same getFieldsSorted(item) method to make sure the field values match up with the column names.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;&amp;lt;table class=&quot;table table-striped&quot; ng-if=&quot;items.length &amp;gt; 0&quot;&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th ng-repeat=&quot;field in getFieldsSorted(items[0])&quot;&amp;gt;
            {{field.description}}            
        &amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;tr ng-repeat=&quot;i in items&quot;&amp;gt;
        &amp;lt;td ng-repeat=&quot;field in getFieldsSorted(i)&quot;&amp;gt;            
            {{field.value}}
        &amp;lt;/td&amp;gt;        
    &amp;lt;/tr&amp;gt;
  &amp;lt;/tbody&amp;gt; 
&amp;lt;/table&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
4. Enable table sorting when clicking on the columns&lt;/h3&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
We&#39;ll use the same &lt;i&gt;getFieldsSorted(item)&lt;/i&gt; method to make sure the field values match up with the column names. To enable sorting we&#39;ll use the &lt;b&gt;ng-click&lt;/b&gt; directive to set both the column name to sort on and the sort direction.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;Sorting by {{toggles.sort.itemsSort.column}}, reverse = {{toggles.sort.itemsSort.reverse}}.
&amp;lt;br&amp;gt;
&amp;lt;table class=&quot;table table-striped&quot; ng-if=&quot;items.length &amp;gt; 0&quot;&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th ng-repeat=&quot;field in getFieldsSorted(items[0])&quot;  ng-click=&quot;toggles.sort.itemsSort.column=&#39;fields.&#39;+field.name+&#39;.value&#39;;toggles.sort.itemsSort.reverse=!toggles.sort.itemsSort.reverse;&quot;&amp;gt;
            {{field.description}}            
        &amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;tr ng-repeat=&quot;i in items&quot;&amp;gt;
        &amp;lt;td ng-repeat=&quot;field in getFieldsSorted(i)&quot;&amp;gt;            
            {{field.value}}
        &amp;lt;/td&amp;gt;        
    &amp;lt;/tr&amp;gt;
  &amp;lt;/tbody&amp;gt; 
&amp;lt;/table&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
Here when a table column is clicked, we are assigning the name of the column to sort on to the &lt;b&gt;toggles.sort.itemsSort.column&lt;/b&gt; variable.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;This is the most important part of this, if you&#39;ve followed so far.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Remember, we are trying to sort the selected field&#39;s values for each item in our $scope.items array. &lt;br /&gt;
&lt;br /&gt;
However the item is not a simple array of strings, it&#39;s a complex object, and so we need to let angular know to sort using a child property of the complex object,&lt;br /&gt;
in our case, by &lt;b&gt;item.fields[name].value          &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So you may be tempted to use this as the column name&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ng-click=&quot;toggles.sort.itemsSort.column=field.name&quot;&lt;/b&gt; &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
however because we are dealing with an array of complex objects this won&#39;t work, instead we&#39;ll use &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;toggles.sort.itemsSort.column=&#39;fields.&#39;+field.name+&#39;.value&#39;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
so angular knows to use the object&#39;s property properly.&lt;br /&gt;
But sorting won&#39;t work yet, because inside the tbody table rows we haven&#39;t enabled it yet.&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
4. Enable sorting of the data&lt;/h3&gt;
&lt;div&gt;
The final step here is to make sure the data is sorted, and for that we&#39;ll use the order by filter to do so. Now the &lt;b&gt;orderBy&lt;/b&gt; filter will properly sort the data from the list of complex objects (items) because it will attempt to sort by &lt;b&gt;item.fields.name.value&lt;/b&gt; (where &#39;name&#39; is automatically changed whenever &lt;b&gt;toggles.sort.itemsSort.column&lt;/b&gt; changes)&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;Sorting by {{toggles.sort.itemsSort.column}}, reverse = {{toggles.sort.itemsSort.reverse}}.
&amp;lt;br&amp;gt;
&amp;lt;table class=&quot;table table-striped&quot; ng-if=&quot;items.length &amp;gt; 0&quot;&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th ng-repeat=&quot;field in getFieldsSorted(items[0])&quot;  ng-click=&quot;toggles.sort.itemsSort.column=&#39;fields.&#39;+field.name+&#39;.value&#39;;toggles.sort.itemsSort.reverse=!toggles.sort.itemsSort.reverse;&quot;&amp;gt;
            {{field.description}}            
        &amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;tr ng-repeat=&quot;i in items | orderBy:toggles.sort.itemsSort.column:toggles.sort.itemsSort.reverse&quot;&amp;gt;
        &amp;lt;td ng-repeat=&quot;field in getFieldsSorted(i)&quot;&amp;gt;            
            {{field.value}}
        &amp;lt;/td&amp;gt;        
    &amp;lt;/tr&amp;gt;
  &amp;lt;/tbody&amp;gt; 

&amp;lt;/table&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;
That&#39;s it. To see the full code example checkout the &lt;a href=&quot;http://codepen.io/anon/pen/gxtbA&quot; target=&quot;_blank&quot;&gt;codepen sourcecode&lt;/a&gt; for this.&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>http://blog.idleworx.com/2014/10/sortable-table-from-array-of-complex.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-VLdCrj0o7us5BmL-ShkkcsxV9F77-sNOjn2qsri6jHEaiedt3CP__AJkOzP3Y5j18xK8XlVt0-YqdMRbOBxmv6lVyV5Mmb0jo4eosJXdN20ZMIb05x_UsTO7CqSh7il30LJ-HGcctqgP/s72-c/angular_table.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-4874952572929287409</guid><pubDate>Wed, 20 Aug 2014 04:01:00 +0000</pubDate><atom:updated>2017-03-10T19:54:41.909-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">angularjs</category><category domain="http://www.blogger.com/atom/ns#">logging</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Creating a flexible Alerting Service with AngularJS (Part 1)</title><description>&lt;small&gt;Using AngularJS 1.2.20, Bootstrap 3, underscore.js&lt;/small&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i.imgur.com/MQR50W5.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i.imgur.com/MQR50W5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
While working on recent AngularJS project I had to come up with an easier way to deal with application messages (error messages, alert messages, debug messages,etc).&lt;br /&gt;
&lt;br /&gt;
If you have a tiny AngularJS app &lt;i&gt;$scope.error = ‘Error Description’;&lt;/i&gt; will do it for sending simple error messages to your controllers, but if you’re using this approach for a larger app you’ll quickly find it’s not a good idea.&lt;br /&gt;
&lt;br /&gt;
While I am sure there are other ways to do this, perhaps better ones, this article will show you how to implement a flexible Alerting/Messaging Service for use in an AngularJS app.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Usage inside Controllers&lt;/h3&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/9d75f46e01e646332bd0.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Why do I have to pass in scope every time?&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The way this Message Service works is it allows you to set one message of each type (info,warning,error,success,debug) ,so 5 in total, on any $scope you pass in. This allows you to set scope specific error messages. This is good because you can have a controller that has a warning message, and another one that has an error message. The messages won&#39;t interfere with each other. &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Usage inside Partials&lt;/h3&gt;
&lt;br /&gt;
To make this really easy, I&#39;ve used bootstrap 3 template code to generate several html templates for the messaging.&lt;br /&gt;
You can simply include the following files (messages.tpl.html) and (debug-messages.tpl.html) in your AngularJS application (assuming you are using the bootstrap 3 framework).&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/7355606a935e5de4a0fb.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/2ac5e096dcf11522b493.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
The above partials can then be embedded anywhere in your app where you want to display an messages. Typical place would be somewhere on top of your main app content. I like to keep the messages and the debug messages separate like this for easier including where needed. Just make sure they are inside the scope for which you are displaying these messages (otherwise the $scope.messages property will be undefined, and no messages will show for this scope).&lt;br /&gt;
&lt;br /&gt;
So for example, if you are using the controller from before&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/9d75f46e01e646332bd0.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
you should be using this code to add the messages to your app.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/3ada8d85631d7bdc7410.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
How the Message Service actually works&lt;/h3&gt;
&lt;br /&gt;
The message service adds a $scope.message property to any $scope for which you invoked the MessageService.init($scope) method. It then keeps track and updates $scope.message any time you call one of the message methods such as MessageService.error($scope,&#39;This is an error&#39;);&lt;br /&gt;
&lt;br /&gt;
And here is the actual Message Service (MessageService.js)&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/c18ce3dc2c4acb3de1bc.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
If you need the angular and underscore.js libraries used in this example, just add the following to your app&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/idleworx/a96c35c25e366cdd2db6.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;
Part 2 - Coming soon ... more complex example, custom error objects, global messages and scope specific messages&lt;br /&gt;
&lt;/h1&gt;
</description><link>http://blog.idleworx.com/2014/08/write-custom-flexible-message-alert.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-837714900041934512</guid><pubDate>Fri, 28 Feb 2014 03:18:00 +0000</pubDate><atom:updated>2017-03-10T19:54:41.914-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">angularjs</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>AngularJS - Best resources for learning ui-router</title><description>ui-router is an angular module that replaces the default routing mechanism. It is more flexible than the default and recommended by the AngularJS community. However it is still in active development&lt;br /&gt;
&lt;br /&gt;
This is a collection of resources about ui-router, from simple to more complex.&lt;br /&gt;
&lt;br /&gt;
ui-router project on git &lt;br /&gt;
&lt;a href=&quot;https://github.com/angular-ui/ui-router&quot;&gt;https://github.com/angular-ui/ui-router&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Intro video to ui-router (5 mins)&lt;br /&gt;
&lt;a href=&quot;https://egghead.io/lessons/angularjs-introduction-ui-router&quot;&gt;https://egghead.io/lessons/angularjs-introduction-ui-router&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Another intro video to ui-router (first 15 minutes). &lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/QETUuZ27N0w?feature=player_detailpage&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
A great article about ui-router (more indepth)&lt;br /&gt;
&lt;a href=&quot;http://www.ng-newsletter.com/posts/angular-ui-router.html&quot;&gt;http://www.ng-newsletter.com/posts/angular-ui-router.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In-depth video about ui-router (50 min) + with &lt;a href=&quot;http://slid.es/timkindberg/ui-router#/&quot;&gt;http://slid.es/timkindberg/ui-router#/&lt;/a&gt;&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/dqJRoh8MnBo?feature=player_detailpage&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Related Resources&lt;/h4&gt;
&lt;br /&gt;
One way to setup authentication in AngularJS&lt;br /&gt;
&lt;a href=&quot;http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app&quot;&gt;http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Builds on the article above, but using ui-router&lt;br /&gt;
&lt;a href=&quot;https://medium.com/opinionated-angularjs/4e927af3a15f&quot;&gt;https://medium.com/opinionated-angularjs/4e927af3a15f&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;yt&quot; id=&quot;watch-headline-title&quot; style=&quot;background-color: transparent; border: 0px none; color: #222222; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px 0px 5px; overflow: hidden; padding: 0px; text-align: start; text-indent: 0px; text-overflow: ellipsis; text-transform: none; white-space: nowrap; word-spacing: 0px; word-wrap: normal;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;watch-title  yt-uix-expander-head&quot; dir=&quot;ltr&quot; id=&quot;eow-title&quot; style=&quot;background-color: transparent; border: 0px none; color: black; cursor: auto; margin: 0px; padding: 0px;&quot; title=&quot;Writing a Massive Angular App at Google   NG Conf&quot;&gt;Video - Writing a Massive Angular App at Google NG Conf (good tips about authentication in the first part)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;a href=&quot;http://www.youtube.com/watch?v=62RvRQuMVyg&quot;&gt;http://www.youtube.com/watch?v=62RvRQuMVyg&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you have additional suggestions, let me know and I will add them here. </description><link>http://blog.idleworx.com/2014/02/angularjs-best-resources-for-learning.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-2174781926947695133</guid><pubDate>Fri, 14 Feb 2014 03:03:00 +0000</pubDate><atom:updated>2017-03-10T19:54:57.409-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>AngularJS Intro in 60 minutes (video)</title><description>&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/i9MHigUZKEM?feature=player_detailpage&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;</description><link>http://blog.idleworx.com/2014/02/angularjs-intro-in-60-minutes-video.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-7228755949920594512</guid><pubDate>Sat, 16 Mar 2013 04:31:00 +0000</pubDate><atom:updated>2017-03-10T19:58:49.797-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>You should update your TableSorter jQuery plugin</title><description>If you&#39;re still using the cool &lt;a href=&quot;http://tablesorter.com/docs/&quot;&gt;jQuery TableSorter&lt;/a&gt; plugin by Christian Bach, be advised that the last update to it was back in 2008 (version 2.0.8 as of today).&lt;br /&gt;
&lt;br /&gt;
There is a newer forked version of &lt;a href=&quot;https://github.com/Mottie/tablesorter&quot;&gt;Table Sorter&lt;/a&gt; on github, v2.7.x that seems to be maintained by someone else and up to date. Docs &lt;a href=&quot;http://mottie.github.com/tablesorter/docs/index.html&quot;&gt;here&lt;/a&gt;.</description><link>http://blog.idleworx.com/2013/03/you-should-update-your-tablesorter.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-42814837646676780</guid><pubDate>Tue, 12 Mar 2013 02:52:00 +0000</pubDate><atom:updated>2017-03-10T20:06:10.288-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Teach a Dog to REST</title><description>A good video on how to build REST APIs the right way.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe src=&quot;http://player.vimeo.com/video/17785736?badge=0&quot; width=&quot;400&quot; height=&quot;300&quot; frameborder=&quot;0&quot; webkitAllowFullScreen mozallowfullscreen allowFullScreen&gt;&lt;/iframe&gt;</description><link>http://blog.idleworx.com/2013/03/teach-dog-to-rest.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-8321301948380244138</guid><pubDate>Fri, 16 Nov 2012 02:57:00 +0000</pubDate><atom:updated>2017-03-10T20:06:10.291-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>The Unbearable Immutability of Java Strings</title><description>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Here is a quick explanation of what an Immutable String is in Java. &lt;/div&gt;
Basically, an immutable string means that the string &#39;object&#39; can&#39;t be changed, but references to it can.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVJJ6kib6mmKhOzMwZT0kc4yjR52SZQGI18Ze1MCpmbIodYsrit_JkonQpD9TrMJ1c1hzT6_xiOibDgT5nu4z_y3Q1t60ArHCQPWROHZOtTsIAXnx-RBNxdKE0HsTKE9hy2HIyeCjZkymO/s1600/theunbearableimmutabilityofstrings.png&quot;&gt;&lt;br /&gt;
&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVJJ6kib6mmKhOzMwZT0kc4yjR52SZQGI18Ze1MCpmbIodYsrit_JkonQpD9TrMJ1c1hzT6_xiOibDgT5nu4z_y3Q1t60ArHCQPWROHZOtTsIAXnx-RBNxdKE0HsTKE9hy2HIyeCjZkymO/s400/theunbearableimmutabilityofstrings.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://blog.idleworx.com/2012/11/the-unbearable-immutability-of-java.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVJJ6kib6mmKhOzMwZT0kc4yjR52SZQGI18Ze1MCpmbIodYsrit_JkonQpD9TrMJ1c1hzT6_xiOibDgT5nu4z_y3Q1t60ArHCQPWROHZOtTsIAXnx-RBNxdKE0HsTKE9hy2HIyeCjZkymO/s72-c/theunbearableimmutabilityofstrings.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-5419101821378678880</guid><pubDate>Sat, 10 Nov 2012 22:24:00 +0000</pubDate><atom:updated>2017-03-10T20:14:45.651-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Jerker Desk Replacement Screws and Bolts</title><description>Yes, there is a &lt;a href=&quot;http://www.ikeahackers.net/2012/01/split-level-jerker-desk.html&quot; target=&quot;_blank&quot;&gt;cult like following&lt;/a&gt; on the internet for IKEA Jerker Desks. &lt;br /&gt;
&lt;br /&gt;
It&#39;s hard to find replacement screws for the desk since it&#39;s discontinued. Here&#39;s a list of the screw sizes I found at Lowe&#39;s that should work with any Jerker desk. I used these to add on some additional shelves (since I only had the screws and bolts that came with the main table part of the desk)&lt;br /&gt;
&lt;br /&gt;
You can find these at your local Lowe&#39;s or HomeDepot store in the METRIC/European section of the nuts and bolts isle. Ask for it, it&#39;s there :-)  &lt;br /&gt;
&lt;br /&gt;
Screws - Hex Cap Screws (&lt;b&gt;Class 8.8 - M6-1.00x50&lt;/b&gt;)&lt;br /&gt;
Nuts - Hex Nuts (&lt;b&gt;Class 8 - M6-1.00&lt;/b&gt;) [option 1]&lt;br /&gt;
Nuts - Insert Lock Nuts (&lt;b&gt;Nylon Class 8 - M6-1.00&lt;/b&gt;)  [option 2]&lt;br /&gt;
Washers - Flat Washers - &lt;b&gt;6mm&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;TIP&lt;/i&gt;: Use the washers between the metal part and the nut for tighter grip]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I got the Jerker desk a while back, as I needed a better desk for programming. I wouldn&#39;t say it&#39;s the most amazing desk ever but it&#39;s comfortamble and makes excellent use of space particularly if you have multiple things you need around eg. scanner, printer, subwoofer, midi keyboard etc. &lt;br /&gt;
&lt;br /&gt;
IKEA has a similar desk on sale called the &lt;a href=&quot;http://www.ikea.com/us/en/catalog/products/40111124/&quot; target=&quot;_blank&quot;&gt;FREDRIK&lt;/a&gt;. Some people seem to think the Jerker desk doesn&#39;t even compare with the FREDERIK, but I don&#39;t know as I&#39;ve never tried it so can&#39;t compare.&lt;br /&gt;
&lt;br /&gt;
So far the Jerker desk is great for what I need. Use your own judgement. &lt;br /&gt;
&lt;br /&gt;
Hope you found this useful in case you are looking to add some additional shelves to your Jerker desk.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://blog.idleworx.com/2012/11/jerker-desk-replacement-screws-and-bolts.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-1639697718509726</guid><pubDate>Thu, 01 Nov 2012 00:03:00 +0000</pubDate><atom:updated>2017-03-22T16:10:47.591-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">spring</category><title>All Spring Schema Configurations and JARs for Spring 2.0, 2.5, 3.0</title><description>This post contains basic info about Spring Schema Configuration XML syntax for different versions of Spring 2.0.x, 2.5.x and 3.0.x.&lt;br /&gt;
&lt;br /&gt;
Not sure why it&#39;s so hard to find this data all put together so here it is. Direct download links for the Spring JARs and the spring xml file header configuration for each version.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Spring 2.0 - October 2006&lt;/h3&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;&lt;beans xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot; xmlns:lang=&quot;http://www.springframework.org/schema/lang&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:util=&quot;http://www.springframework.org/schema/util&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.springframework.org/schema/beans&quot; xsi:schemalocation=&quot;
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
&quot;&gt;
&lt;!-- &lt;bean/&gt; definitions here --&gt;
&lt;/beans&gt;
&lt;/pre&gt;&lt;br /&gt;
Direct Download Link: &lt;a href=&quot;http://sourceforge.net/projects/springframework/files/springframework-2/2.0.8/&quot; target=&quot;_blank&quot;&gt;Spring Framework 2.0.8&lt;/a&gt; (latest Spring 2.0.x release) &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Spring 2.5 - November 2007&lt;/h3&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;&lt;beans xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot; xmlns:jms=&quot;http://www.springframework.org/schema/jms&quot; xmlns:lang=&quot;http://www.springframework.org/schema/lang&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:util=&quot;http://www.springframework.org/schema/util&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.springframework.org/schema/beans&quot; xsi:schemalocation=&quot;
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
&quot;&gt;
      &lt;!-- &lt;bean/&gt; definitions here --&gt;
&lt;/beans&gt;
&lt;/pre&gt;&lt;br /&gt;
Direct Download Link: &lt;a href=&quot;http://spring-framework-2.5.6.sec03.zip/&quot;&gt;spring-framework-2.5.6.SEC03.zip&lt;/a&gt; (latest Spring 2.5.x maintenance release)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt;The only difference between the syntax for Spring 2.0 and 2.5 seems to be the addition of the context schema in 2.5. &lt;br /&gt;
Also as of Spring 2.5, Spring provides support for configuring the MVC framework components using &lt;a href=&quot;http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation&quot; target=&quot;_blank&quot;&gt;annotations&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Spring 3.0 - December 2009&lt;/h3&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;&lt;beans xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot; xmlns:jms=&quot;http://www.springframework.org/schema/jms&quot; xmlns:lang=&quot;http://www.springframework.org/schema/lang&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:util=&quot;http://www.springframework.org/schema/util&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.springframework.org/schema/beans&quot; xsi:schemalocation=&quot;
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
&quot;&gt;
 &lt;property-placeholder&gt;
 &lt;annotation-config&gt;
 &lt;!-- &lt;bean/&gt; definitions here --&gt;
&lt;/annotation-config&gt;&lt;/property-placeholder&gt;&lt;/beans&gt;
&lt;/pre&gt;&lt;br /&gt;
Direct Download Link: &lt;a href=&quot;http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-3.1.3.RELEASE.zip&quot; target=&quot;_blank&quot;&gt;spring-framework-3.1.3.RELEASE.zip&lt;/a&gt; (current production release)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt;The spring.jar that contained almost the entire framework is no longer provided in Spring 3.0 so you must include each jar as needed separately. &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;New Features in Spring 3.0&lt;/h4&gt;&lt;br /&gt;
Spring 3.0 also introduced a few &lt;a href=&quot;http://static.springsource.org/spring/docs/3.0.x/reference/new-in-3.html&quot; target=&quot;_blank&quot;&gt;new features&lt;/a&gt; such as additional annotations for MVC, server-side support for building RESTful applications, the &lt;a href=&quot;http://static.springsource.org/spring/docs/3.0.x/reference/expressions.html&quot; target=&quot;_blank&quot;&gt;Spring Expression Language&lt;/a&gt; and integration of some core features from the &lt;a href=&quot;http://javaconfig.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;JavaConfig&lt;/a&gt; project.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Useful Links&lt;/h3&gt;&lt;a href=&quot;http://static.springsource.org/spring/docs/2.0.x/reference/index.html&quot; target=&quot;_blank&quot;&gt;Spring 2.0.x Reference&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://static.springsource.org/spring/docs/2.0.x/reference/xsd-config.html&quot; target=&quot;_blank&quot;&gt;Spring 2.0.x Schema Configuration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://static.springsource.org/spring/docs/2.5.x/reference/index.html&quot; target=&quot;_blank&quot;&gt;Spring 2.5.x Reference&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://static.springsource.org/spring/docs/2.5.x/reference/xsd-config.html&quot; target=&quot;_blank&quot;&gt;Spring 2.5.x Schema Configuration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/&quot; target=&quot;_blank&quot;&gt;Spring 3.0.x Reference&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://static.springsource.org/spring/docs/3.0.x/reference/xsd-config.html&quot; target=&quot;_blank&quot;&gt;Spring 3.0.x Schema Configuration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://blog.springsource.com/2009/12/16/spring-framework-3-0-goes-ga/&quot; target=&quot;_blank&quot;&gt;New in Spring 3.0 &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.springsource.org/download&quot; target=&quot;_blank&quot;&gt;Spring Main Download Page&lt;/a&gt;</description><link>http://blog.idleworx.com/2012/10/all-spring-schema-configurations-and.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-1094918308884475157</guid><pubDate>Thu, 12 Apr 2012 23:12:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.217-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Android Development Is Not Easy</title><description>As a seasoned software engineer I spent a good number of hours over the past week trying to figure out how to do the following on an Android device.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem:&lt;/b&gt; Create an android application that checks a local SQLite database at a given interval (say every day @ 12:00 am), does something with that data, then displays a notification to the user.&lt;br /&gt;
&lt;br /&gt;
Seemed like a trivial thing to do.&lt;br /&gt;
&lt;br /&gt;
Initially I thought I would need only a Service that my Activity starts. I was wrong.&lt;br /&gt;
&lt;br /&gt;
After reading more thoroughly through the Android API documentation, numerous stackoverflow articles, and some trial and error I figured it out.&lt;br /&gt;
&lt;br /&gt;
In order to do this on android you have to understand the following concepts:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;BroadcastReceivers&lt;/li&gt;
&lt;li&gt;Services (more specifically IntentServices)&lt;/li&gt;
&lt;li&gt;Intents (more specifically PendingIntents)&lt;/li&gt;
&lt;li&gt;Reading/Writing to an SQLite database&lt;/li&gt;
&lt;li&gt;The AlarmManager&amp;nbsp;&lt;/li&gt;
&lt;li&gt;How notifications work&lt;/li&gt;
&lt;li&gt;+ a few other things&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
The short answer is the following.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt; You have to implement a custom broadcast receiver, that uses the AlarmManager to schedule a PendingIntent that starts a custom Service which does the work, which creates a Notification at (or around) a set time for the user to click on.&lt;br /&gt;
&lt;br /&gt;
There&#39;s some quirks too you have to consider:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;How do you make sure your app continues to run after the user reboots the android device?&lt;/li&gt;
&lt;li&gt;How do you schedule the first Notification after your app is started by the user for the first time?&lt;/li&gt;
&lt;li&gt;When do you schedule the alarm to run? What happens if the device is off?&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
So if you just got an awesome idea for an Android app, great. I hope you&#39;ll be able to use your skills to build it and make it a success. But be warned, you need not only coding skills, but&amp;nbsp;passion&amp;nbsp;and patience, and don&#39;t fool yourself into thinking that it will take you a few hours.&lt;br /&gt;
&lt;br /&gt;
Building an app (a non trivial app that is) is one thing. Building an android application that is well designed and coded, runs well, and provides a true service to your users is hard.&lt;br /&gt;
&lt;br /&gt;
If you don&#39;t have the luxury of time, the patience required, or the necessary skills to build an Android Application yourself, don&#39;t sweat it, it&#39;s not easy stuff.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;So do yourself a favor and &lt;a href=&quot;http://www.idleworx.com/&quot; target=&quot;_blank&quot;&gt;hire a developer&lt;/a&gt;&amp;nbsp;to build it for you.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;</description><link>http://blog.idleworx.com/2012/04/android-development-is-not-easy.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-4455820721088616223</guid><pubDate>Mon, 06 Feb 2012 00:50:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.224-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>The Do Not Track movement is useless</title><description>&lt;h2&gt;
... or why privacy is your own responsibility&lt;/h2&gt;
The &lt;b&gt;Do Not Track&lt;/b&gt; movement (&lt;a href=&quot;http://donottrack.us/&quot;&gt;donottrack.us&lt;/a&gt;)&amp;nbsp;is, according to their website&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&quot;a technology and policy proposal that enables users to opt out of tracking by websites they do not visit&quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
and from a recent article in USA Today,&amp;nbsp;&lt;a href=&quot;http://www.usatoday.com/tech/news/story/2011-11-15/facebook-privacy-tracking-data/51225112/1&quot; target=&quot;_blank&quot;&gt;How Facebook tracks you across the web&lt;/a&gt;&amp;nbsp;we find out the following&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&quot;Facebook&#39;s efforts to track the browsing habits of visitors to its site have made the company a player in the &quot;Do Not Track&quot; debate, which focuses on whether consumers should be able to prevent websites from tracking the consumers&#39; online activity.&quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Companies like Facebook, Google, etc have a vested interest in finding out as much information about &lt;b&gt;EVERYTHING&lt;/b&gt; you do.&amp;nbsp;That&#39;s how they make money. So any &lt;i&gt;movement&lt;/i&gt;&amp;nbsp;that proposes these companies self-regulate and take more care of our&amp;nbsp;privacy needs is simply useless. &lt;br /&gt;
&lt;br /&gt;
Even if regulation was passed forcing these companies to allow users to opt out of tracking,&amp;nbsp;that doesn&#39;t mean it wouldn&#39;t still occur.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href=&quot;http://donottrack.us/&quot;&gt;donottrack.us&lt;/a&gt; website also mentions that&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&quot;Several large third parties have already committed to honor Do Not Track ... &quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So what? Does that mean anything really?&lt;br /&gt;
&lt;br /&gt;
What do you know about what they do with this information even if they &quot;&lt;i&gt;committed&quot;&lt;/i&gt;&amp;nbsp;to work against their own self and business interests&amp;nbsp;by not tracking you?&lt;br /&gt;
&lt;br /&gt;
I&#39;ll tell you. Absolutely nothing!&lt;br /&gt;
&lt;br /&gt;
Do you have a signed contract with them that says they can never track you?&amp;nbsp;Is there an actual law&amp;nbsp;that prevents them from tracking you? No?&amp;nbsp;Then stop daydreaming.&lt;br /&gt;
&lt;br /&gt;
When it comes to personal privacy and security, you can&#39;t outsource it (especially to those who have an interest in your lack of privacy). There&#39;s no easy way.
&lt;br /&gt;
&lt;br /&gt;
So if you care about &lt;a href=&quot;http://www.schneier.com/blog/archives/2009/12/my_reaction_to.html&quot; target=&quot;_blank&quot;&gt;your privacy&lt;/a&gt;, &lt;a href=&quot;http://www.documentary24.com/privacy-is-dead-get-over-it--317/&quot; target=&quot;_blank&quot;&gt;educate yourself&lt;/a&gt;&amp;nbsp;and &lt;a href=&quot;http://torrentfreak.com/which-vpn-providers-really-take-anonymity-seriously-111007/&quot; target=&quot;_blank&quot;&gt;protect yourself&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://blog.idleworx.com/2012/02/do-not-track-movement-is-useless.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-5381207489493623322</guid><pubDate>Thu, 02 Feb 2012 06:22:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.228-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Goodbye Delicious, Hello Pinboard</title><description>&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;Goodbye Delicious&lt;/span&gt;&lt;/h2&gt;
There are two types of people in the world, those who rarely save bookmarks, and those who have thousands. If you&#39;re like me, you probably have thousands or at least a few hundred. For me it&#39;s more exactly 4466 bookmarks at last count. (If you&#39;re not like me, a &lt;i&gt;bookmark hoarder&lt;/i&gt;, then you probably want to skip this article.)&lt;br /&gt;
&lt;br /&gt;
Over the past 10-15 years I&#39;ve collected tons of bookmarks because I like to keep track of cool, useful and interesting things I find online so if I ever want to go back to them I can.&lt;br /&gt;
&lt;br /&gt;
I&#39;ve spent countless hours over the years keeping things clean, ordered and organized so I can actually make use of this information. As you can imagine if you don&#39;t keep this many bookmarks organized and neat there&#39;s absolutely no point in saving them in the first place, since you won&#39;t be able to find anything if you so choose at a later time.&lt;br /&gt;
&lt;br /&gt;
Bookmarks, when used correctly are nothing more than a self maintained cache of the things you&#39;ve found most interesting or useful. Thus they are a treasure trove of data for various services such as &amp;nbsp;&lt;a href=&quot;http://delicious.com/&quot; target=&quot;_blank&quot;&gt;delicious&lt;/a&gt;&amp;nbsp;or &lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_social_bookmarking_websites&quot; target=&quot;_blank&quot;&gt;various others&lt;/a&gt; which have capitalized on this.&lt;br /&gt;
&lt;br /&gt;
Delicious was founded in 2003, and was essentially the company that introduced social bookmarking and tagging to the masses. That said and done I didn&#39;t really get on board with them until a few years ago when I outgrew my&amp;nbsp;bookmarking&amp;nbsp;needs. Trying to manage several thousand bookmarks&amp;nbsp;across&amp;nbsp;multiple browsers and multiple computers does that to you.&lt;br /&gt;
&lt;br /&gt;
But delicious has not delivered and has recently started to fall short, in part due to Yahoo firing the delicious team, and its subsequent purchase by &lt;a href=&quot;http://www.avos.com/delicious-press-release/&quot; target=&quot;_blank&quot;&gt;Youtube founders&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here&#39;s just a few problems I found:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Slow syncing of bookmarks in browser&lt;/li&gt;
&lt;li&gt;Having to sometimes log in every day&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Firefox addons would stop working after upgrading to certain version of Firefox&lt;/li&gt;
&lt;li&gt;The pain and waste of time trying to find a way to mark all my bookmarks private when bookmarking through a browser plugin. Why, delicious? Why?&lt;/li&gt;
&lt;li&gt;Inconsistent tag naming - You could use spaces in an older versions of the Firefox plugin, but only commas in newer versions. Because it wasn&#39;t made clear, myself and I&#39;m sure plenty of others, had had to go through tons of delicious bookmarks and convert tags like &quot;programming jsp reference useful&quot; into the 4 separate tags they should have been in the first place. Not cool)&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
And there were other &lt;a href=&quot;http://blog.earth2marsh.com/2012/01/dearest-delicious.html&quot; target=&quot;_blank&quot;&gt;unhappy campers&lt;/a&gt;.
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;Hello Pinboard&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
As delicious was going down, I learned of other social bookmarking sites, &lt;a href=&quot;http://pinboard.in/&quot;&gt;pinboard.in&lt;/a&gt; being one that caught my attention.&lt;br /&gt;
&lt;br /&gt;
Throughout the years, I had migrated over from IE Favorites to Firefox Bookmarks to delicious bookmarks. I had hand&amp;nbsp;curated my bookmarks and cleaned them up with link checkers to remove expired ones. It was time to move on to something better.&lt;br /&gt;
&lt;br /&gt;
So last night, I finally made the switch and created an account on pinboard.in. It&#39;s not free mind you&amp;nbsp;(&lt;i&gt;there is a one time fee of about $9&lt;/i&gt;), but from everything I read it&#39;s worth it &amp;nbsp;Not to mention &lt;a href=&quot;http://web.appstorm.net/general/interviews/interview-meet-maciej-ceglowski-of-pinboard-in/&quot; target=&quot;_blank&quot;&gt;the guy behind it&lt;/a&gt; seems like a great chap and has his stuff together.&lt;br /&gt;
&lt;br /&gt;
And from the first looks, I love it.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Importing almost 4500 bookmarks from both firefox and delicious was painless. Took a few minutes.&lt;/li&gt;
&lt;li&gt;Interface is great, simple, minimal and quick, exactly what I wanted&lt;/li&gt;
&lt;li&gt;Great default privacy settings give you the ability to &#39;add bookmarks as private by default&#39;&lt;/li&gt;
&lt;li&gt;&#39;enable public profile&#39; is OFF by default&lt;/li&gt;
&lt;li&gt;and more&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
I did notice there was no &lt;i&gt;easy&lt;/i&gt; way to rename a tag in pinboard (&lt;a href=&quot;http://pinboard.in/faq#rename_tag&quot; target=&quot;_blank&quot;&gt;there is a way though&lt;/a&gt;), but I&#39;m planning to play around with the Pinboard API soon and see what I can cook up.&lt;br /&gt;&lt;br /&gt;I&#39;m sure pinboard is not perfect, but hey, it is the best I&#39;ve found so far for my bookmarking needs.&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>http://blog.idleworx.com/2012/02/goodbye-delicious-hello-pinboard.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-6374180030512657660</guid><pubDate>Wed, 18 Jan 2012 03:31:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.235-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>A simple birthday reminder app</title><description>Are you looking for an easy breazy birthday reminder app to keep track of all your friends&#39; birthdays that you seem to forget every year? Well, look no further.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The time has come for you to get your self organized and never forget another birthday again. Check out &lt;a href=&quot;http://beta.birthdayduck.com/&quot;&gt;http://beta.birthdayduck.com&lt;/a&gt; a simple, clean and useful birthday reminder service from IdleWorx&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Here&#39;s a screenshot&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5kKE4iWsV2jcqVohsBsnuk7QUtUIaNnwqfiMoiMCL578kKPNkGalHtacoxUCfTrXCT1rL077vCLGhjjW2yxkjiLXVuNwhr83Moan0uU3nixqHuJ1T9_DBSZ-YuGmDlX3Ei1s3xWKOQ82Z/s1600/main.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5kKE4iWsV2jcqVohsBsnuk7QUtUIaNnwqfiMoiMCL578kKPNkGalHtacoxUCfTrXCT1rL077vCLGhjjW2yxkjiLXVuNwhr83Moan0uU3nixqHuJ1T9_DBSZ-YuGmDlX3Ei1s3xWKOQ82Z/s320/main.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
It has the essential features you need in a birthday reminder application:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Reminders by email&lt;/li&gt;
&lt;li&gt;Reminders by SMS/text message&lt;/li&gt;
&lt;li&gt;A simple way to add names ands birthdays&lt;/li&gt;
&lt;li&gt;Import contacts from Facebook&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
No bells and whistles. birthdayduck.com aims to help you organize your life, by making it very easy to remember people&#39;s birthdays.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
It works like a birthday reminder calendar, except you won&#39;t need to worry about it all the time. The application will send you reminders by email and sms before someone&#39;s birthday.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We&#39;re currently in &lt;b&gt;beta&lt;/b&gt;, and getting ready to launch soon.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;If you sign up now at
&amp;nbsp;&lt;a href=&quot;http://beta.birthdayduck.com/&quot;&gt;http://beta.birthdayduck.com&lt;/a&gt;&amp;nbsp;&amp;nbsp;and you are one of the first 50 sign-ups you&#39;ll receive a free lifetime account on birthdayduck.com once we launch.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;</description><link>http://blog.idleworx.com/2012/01/birthday-reminder-app.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5kKE4iWsV2jcqVohsBsnuk7QUtUIaNnwqfiMoiMCL578kKPNkGalHtacoxUCfTrXCT1rL077vCLGhjjW2yxkjiLXVuNwhr83Moan0uU3nixqHuJ1T9_DBSZ-YuGmDlX3Ei1s3xWKOQ82Z/s72-c/main.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-3294680615175376737</guid><pubDate>Thu, 29 Dec 2011 00:35:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.221-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">interesting</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">videos</category><title>How algorithms shape our world (video)</title><description>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/TDaFwnOiKVE?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
Kevin Slavin argues that we&#39;re living in a world designed for -- and 
increasingly controlled by -- algorithms. In this riveting talk from 
TEDGlobal, he shows how these complex computer programs determine: 
espionage tactics, stock prices, movie scripts, and architecture.</description><link>http://blog.idleworx.com/2011/12/how-algorithms-shape-our-world-video.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-6114301729051161879</guid><pubDate>Wed, 21 Dec 2011 02:05:00 +0000</pubDate><atom:updated>2017-03-14T14:46:10.231-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">opinions</category><title>Your time is not worth that much</title><description>I noticed a lot of people in the startup/programming/HN community seem to measure their time in the equivalent of how much money they could be making during that time.&lt;br /&gt;
&lt;br /&gt;
For example, you ask a friend to do something for you that takes 2 hours, and they tell you that in those 2 hours they could be making
300$ because that&#39;s their hourly rate if they were doing freelance work. So essentially if they aren&#39;t paid for these 2 hours they are basically
loosing 300$.&lt;br /&gt;
&lt;br /&gt;
I say this way of estimating how much your time is worth is flawed.&lt;br /&gt;
&lt;br /&gt;
The only time this estimate is true is when you have a guy waiting at your door 24/7 for you to open it and give you work, and let you charge him 150$/hr for that work (per the example above).&lt;br /&gt;
&lt;br /&gt;
Given any other time, your time estimate is probably way off. Because if you don&#39;t have work available NOW at the rate you&#39;re estimating yourself to be worth, your time is just not worth as much as you think it is.
In fact, if you don&#39;t have any work lined up for that rate, your time is worth almost nothing. It&#39;s free time.&lt;br /&gt;
&lt;br /&gt;
Could you be making money during your free time? Yes, however if you are not ready at that very moment to take on the work at your going rate, your lost opportunity cost is not 150$/hr, but 0$.&lt;br /&gt;
&lt;br /&gt;
The other problem with correctly estimating what your time is worth is how easy it is easy to overestimate. I mean hey, in this next hour that I don&#39;t do anything I could be making a million dollars by winning the lottery. 
So my hourly rate is a million dollars. Just like the example above, that rate IS possible, but highly unprobable not to mention ridiculously unsustainable.&lt;br /&gt;
&lt;br /&gt;
To dig in further, the wiki informs us that:&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&quot;The notion of opportunity cost plays a crucial part in ensuring that scarce resources are used efficiently&quot;&amp;nbsp;&lt;/blockquote&gt;
&lt;br /&gt;
And that&#39;s a good thing. If you&#39;re wasting your time on the couch picking your nose, you could be doing much better things with your time (Eg. creating something useful for others and getting paid for it too)&lt;br /&gt;
&lt;br /&gt;
Some people however have the tendency to put a dolar value on &lt;b&gt;EVERYTHING&lt;/b&gt; in their lives. And sadly it&#39;s a rather limited world view when everything has a dollar value and an opportunity cost.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
News Flash: Not everything in life has a dollar value&lt;/h3&gt;
&lt;br /&gt;
The wiki has a fairly straight forward example of this&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&quot;Opportunity costs are not always measured in monetary units or being able to produce one good over another. 
For instance, an individual could choose not to mow his or her lawn, in an attempt to create a prairie land for additional wild life. Neighbors of this individual may see this as unsightly, and want the lawn to be mowed. In this case, the opportunity cost of additional wild life is unhappy neighbors.&quot;
&lt;/blockquote&gt;
&lt;br /&gt;
We are not robots and life is not a well written ruby script (as some would like to believe).&lt;br /&gt;
&lt;br /&gt;
You can always look at everything in terms of the lost opportunity cost (and the dollar value associated with it), however, often the lost opportunity cost in dollars is far less valuable as an indicator of how much your time is really worth, and in some cases it can&#39;t even be used to accurately describe the lost opportunity cost, such as the opportunity cost of non-tangible things.&lt;br /&gt;
&lt;br /&gt;
For example, spending 2 hours playing with your kids or volunteering and genuinely helping out another human being, is &lt;b&gt;INFINITELY&lt;/b&gt; more important, beneficial and fulfilling than your lost opportunity cost of 300$ that you could be making doing freelance work.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So to sum it up, while it&#39;s good to have a perspective about how much your time is worth, don&#39;t over do it.&lt;br /&gt;
&lt;br /&gt;
There are obvious cases when estimating your time makes perfect sense, but breaking down your entire waking time into lost opportunity costs is a bit too much in my opinion.&lt;br /&gt;
&lt;br /&gt;
Just like with most things in life, aim for moderation.</description><link>http://blog.idleworx.com/2011/12/your-time-is-not-worth-that-much.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-8223264219872265851</guid><pubDate>Sat, 01 Oct 2011 16:16:00 +0000</pubDate><atom:updated>2017-03-15T21:00:14.738-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">agile</category><category domain="http://www.blogger.com/atom/ns#">funny</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Agile Hitler is not Happy</title><description>&lt;iframe width=&quot;420&quot; height=&quot;315&quot; src=&quot;http://www.youtube.com/embed/l1wKO3rID9g&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;</description><link>http://blog.idleworx.com/2011/10/agile-hitler-is-not-happy.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/l1wKO3rID9g/default.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-2854899576369654261</guid><pubDate>Sat, 24 Sep 2011 01:01:00 +0000</pubDate><atom:updated>2017-03-15T21:00:14.730-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dao</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">mybatis</category><title>MyBatis DAO Example Code Tutorial</title><description>&lt;p&gt;This tutorial will show how how to integrate MyBatis with the Data Access Object pattern (DAO) and MySQL for use in Java Web Apps.&lt;/p&gt;

&lt;p&gt;In case you&#39;re not familiar, MyBatis is the new version of the iBatis Data Mapper Java Framework, which allows you to use a relational database with object-oriented applications.&lt;/p&gt;

&lt;p&gt;If you&#39;re not familiar with the DAO pattern or the benefits of using it read more about it here &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-genericdao.html&quot; target=&quot;_blank&quot;&gt;Generic implementation of the DAO pattern&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Full code of this mybatis dao example tutorial is available on &lt;a href=&quot;https://github.com/idleworx/MyBatisDAOHelper&quot; target=&quot;_blank&quot;&gt;github here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;Step 1 - Define the interface&lt;/h2&gt;
&lt;p&gt;
Create an IParentDAO interface to define the main method calls for all objects. This interface can be used as the parent for various DAO implementations. Here are the default CRUD methods that all objects will have
&lt;/p&gt;

&lt;pre&gt;
get(id)
getByName(name)
getAll()
create(obj)
update(object)
delete(id)
&lt;/pre&gt;

&lt;p&gt;Create the IParentDAO.java class &lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

public interface IParentDAO&amp;lt;T, PK&amp;gt;{
 public T get(PK id) throws PersistenceException;//get obj of type T by the primary key &#39;id&#39; 
 public T getByName(String name) throws PersistenceException;//get obj of type T by the &#39;name&#39; field, if one exists for that table
 public ArrayList&amp;lt;T&amp;gt; getAll() throws PersistenceException;//get all objects of type T
 public int create(T objInstance) throws PersistenceException;//insert an object of type T into the database
 int update(T transientObject) throws PersistenceException; //update an object of type T    
 int delete(PK id)  throws PersistenceException;//delete an object of type T
}

&lt;/pre&gt;


&lt;h2&gt;Step 2 - Create the base class&lt;/h2&gt;

&lt;p&gt;Create the MyBatisDAO abstract base class. This will be the default MyBatis implementation of the DAO. You can of course write a different one for JDBC, Spring etc. &lt;i&gt;Feel free to remove the logging code if you don&#39;t need it. I used &lt;a href=&quot;http://logback.qos.ch/&quot; target=&quot;_blank&quot;&gt;Logback&lt;/a&gt; for that.&lt;/i&gt;&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

import java.util.ArrayList;

import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** 
 *  Class contains all the basic CRUD related methods which are inherited by all objects
 *  Children daos should generally not overwrite these method but add extra ones as needed.  
 */
public abstract class MyBatisDAO&amp;lt;T, PK&amp;gt; implements IParentDAO&amp;lt;T, PK&amp;gt;{
 
 private static Logger log = LoggerFactory.getLogger(MyBatisDAO.class);
 private static final String NAMESPACE = &amp;quot;mappers&amp;quot;; 
 
 private SqlSessionFactory sf; //reference to mybatis session factory 
 private Class&amp;lt;T&amp;gt; type;
  
 /** 
  * Define prefixes for easier naming convetions between XML mapper files and the DAO class 
  **/ 
 public static final String PREFIX_SELECT_QUERY = &amp;quot;get&amp;quot;;     //prefix of select queries in mapper files (eg. getAddressType) 
 public static final String PREFIX_INSERT_QUERY = &amp;quot;create&amp;quot;; //prefix of create queries in mapper files (eg. createAddressType)
 public static final String PREFIX_UPDATE_QUERY = &amp;quot;update&amp;quot;;  //prefix of update queries in mapper files (eg. updateAddressType)
 public static final String PREFIX_DELETE_QUERY = &amp;quot;delete&amp;quot;;  //prefix of delete queries in mapper files (eg. deleteAddressType)
 
 /** Default Constructor */
    public MyBatisDAO(Class&amp;lt;T&amp;gt; type,SqlSessionFactory sf) {
        this.type = type;
        this.sf = sf;
        if(sf==null)
   log.error(&amp;quot;Error: Could not instantiate MyBatisDAO. Loading myBatis sessionFactory failed.&amp;quot;);  
    }
    
    /** Use this method to get a session factory for using in any methods impelmented in child dao classes */
    protected SqlSessionFactory getSessionFactory() {
  return sf;
 }

    /** 
     *  Default get by id method. 
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt; 
     *  Almost all objects in the db will 
     *  need this (except mapping tables for multiple joins, which you 
     *  probably shouldn&#39;t even have as objects in your model, since proper 
     *  MyBatis mappings can take care of that).
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;
     *  Example: 
     *  &amp;lt;/br&amp;gt;
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;select id=&amp;quot;getCarInfo&amp;quot; ...  
     */
    public T get(PK id) throws PersistenceException {
        
     SqlSession session = sf.openSession(); 
     T obj = null;
  try
  {  
   String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_SELECT_QUERY+this.type.getSimpleName();  //If the object&#39;s calls name is AddressType.java, this matches the mapper query id: &amp;quot;namespace.getAddressType&amp;quot;
   obj = (T)session.selectOne(query,id);      
  }
  finally
  {
   session.close();
  }
  return obj;
    }
    
    /** 
     *  Method returns all rows for this object.
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  Example:
     *  &amp;lt;/br&amp;gt;  
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;select id=&amp;quot;getAllCarInfo&amp;quot; ...  
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  SQL Executed: select * from [tablename]
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  Notes:
     *  &amp;lt;/br&amp;gt;   
     *  Consider overdiding this method in order to handle large numbers of objects 
     *  with multiple references.  
     *  LAZY LOADING should be enabled in this case, otherwise you might run out of memory (eg. get all UserAccounts if the table has 1,000,000 rows)
     *  look into the aggresiveLazyLoading property 
     *  */
    public ArrayList&amp;lt;T&amp;gt; getAll() throws PersistenceException {
        
     SqlSession session = sf.openSession(); 
     ArrayList&amp;lt;T&amp;gt; list = null;
  try
  {     
   String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_SELECT_QUERY+&amp;quot;All&amp;quot;+this.type.getSimpleName();
   list = (ArrayList&amp;lt;T&amp;gt;)session.selectList(query); 
  }
  finally
  {
   session.close();
  }   
  return list;
    }
    
    /** 
     *  Method returns first object which matches the given name (exact match).
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  It&#39;s up to you to decide what constitutes an object&#39;s name. Typically you would have a 
     *  NAME column in the table, but not all objects have this. Generally this method should be overriden (if you need it at all)
     *  in the child dao class.
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;
     *  Example:
     *  &amp;lt;/br&amp;gt;  
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;select id=&amp;quot;getCarInfoByName&amp;quot; ...  
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  SQL Executed (example): select * from [tablename] where NAME = ? 
     *  
     */
    public T getByName(String name) throws PersistenceException {
        
     SqlSession session = sf.openSession();
     T obj = null;
  try
  { 
   String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_SELECT_QUERY+this.type.getSimpleName()+&amp;quot;ByName&amp;quot;;
   obj = (T)session.selectOne(query,name);   
  }
  finally
  {
   session.close();
  }
  return obj;
    }
    
    
    /** 
     *  Method inserts the object into the table.
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;
     *  You will usually override this method, especially if you&#39;re inserting associated objects.
     *  &amp;lt;/br&amp;gt; 
     *  Example:
     *  &amp;lt;/br&amp;gt;  
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;insert id=&amp;quot;createCarInfo&amp;quot; ...  
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  SQL Executed (example): insert into [tablename] (fieldname1,fieldname2,...) values(value1,value2...) ... 
     *  
     */
    public int create(T o) throws PersistenceException{        
     SqlSession session = sf.openSession();
     Integer status = null;
     try
  {   
      String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_INSERT_QUERY+o.getClass().getSimpleName();
   status = (Integer)session.insert(query,o);
   session.commit();   
  }
  finally
  {
   session.close();
  }  
  return status;
    }
    
    
    /** 
     *  Method updates the object by id.
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;
     *  You will usually override this method. But it can be used for simple objects.
     *  &amp;lt;/br&amp;gt; 
     *  Example:
     *  &amp;lt;/br&amp;gt;  
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;update id=&amp;quot;updateCarInfo&amp;quot; ...  
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  SQL Executed (example): update [tablename] set fieldname1 = value1 where id = #{id} 
     *  
     */
    public int update(T o)throws PersistenceException {
        
     SqlSession session = sf.openSession();
  Integer status = null;
     try
  {   
   String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_UPDATE_QUERY+o.getClass().getSimpleName();
      status = session.update(query,o);
   session.commit();
   
  }
  finally
  {
   session.close();
  } 
  return status;
     
    }

    
    /** 
     *  Method deletes the object by id.
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;
     *  Example:
     *  &amp;lt;/br&amp;gt;  
     *  If your DAO object is called CarInfo.java, 
     *  the corresponding mapper query id should be: &amp;amp;lt;delete id=&amp;quot;deleteCarInfo&amp;quot; ...  
     *  &amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;  
     *  SQL Executed (example): update [tablename] set fieldname1 = value1 where id = #{id} 
     *  
     */
    public int delete(PK id)  throws PersistenceException{
  SqlSession session = sf.openSession();
  Integer status = null;
  try
  {   
   String query = NAMESPACE+&amp;quot;.&amp;quot;+PREFIX_DELETE_QUERY+this.type.getSimpleName();
   status = session.delete(query,id);
   session.commit();
  } 
  finally
  {
   session.close();
  } 
  return status;
  
    }
}

&lt;/pre&gt;

&lt;h3&gt;Naming Convetions&lt;/h3&gt;

&lt;p&gt;You&#39;ll notice there are four prefix constants defined in the class above.&lt;/p&gt;

&lt;p&gt;The reason for this is to keep consistency between the sql query ids you will define in the mybatis mapper.xml files (see Step 4) and the method names defined in the MyBatisDAO class we&#39;re implementing.&lt;/p&gt;

&lt;p&gt;This won&#39;t work exactly like ActiveRecord or similar frameworks where there is a pluralization engine but it will still simplify things a lot. &lt;/p&gt;

&lt;p&gt;For example, if you have an object called Status for which you will create a DAO, you will have to define the following mybatis querries&lt;/p&gt;

&lt;style&gt;
#tableNamingConvetions{
        text-align: left;
 border-spacing: 0px;
 border: 1px solid #aeb3b6;
 border-collapse: collapse;
        width:90%;        
}
#tableNamingConvetions td,th{
   font-size:12px;
}

&lt;/style&gt;

&lt;table id=&quot;tableNamingConvetions&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
  &lt;th&gt;Java Method&lt;/th&gt;
  &lt;th&gt;MyBatis Query Id&lt;/th&gt;
  &lt;th&gt;Convention&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.get(1)&lt;/td&gt;
  &lt;td&gt;&amp;lt;select id=&quot;getStatus&quot; ...&lt;/td&gt;
  &lt;td&gt;get&lt;b&gt;ClassName&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.getAll()&lt;/td&gt;
  &lt;td&gt;&amp;lt;select id=&quot;getAllStatus&quot; ...&lt;/td&gt;
  &lt;td&gt;getAll&lt;b&gt;ClassName&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.getByName(String name)&lt;/td&gt;
  &lt;td&gt;&amp;lt;select id=&quot;getStatusByName&quot; ...&lt;/td&gt;
  &lt;td&gt;get&lt;b&gt;ClassName&lt;/b&gt;ByName&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.create(obj)&lt;/td&gt;
  &lt;td&gt;&amp;lt;insert id=&quot;createStatus&quot; ...&lt;/td&gt;
  &lt;td&gt;create&lt;b&gt;ClassName&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.update(obj)&lt;/td&gt;
  &lt;td&gt;&amp;lt;update id=&quot;updateStatus&quot; ...&lt;/td&gt;
  &lt;td&gt;update&lt;b&gt;ClassName&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;dao.delete(id)&lt;/td&gt;
  &lt;td&gt;&amp;lt;delete id=&quot;deleteStatus&quot; ...&lt;/td&gt;
  &lt;td&gt;delete&lt;b&gt;ClassName&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Don&#39;t worry, this will make a lot more sense once you get to &lt;b&gt;Step 4&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;Step 3 - Write the actual DAO classes&lt;/h2&gt;

&lt;p&gt;Now you need to implement your concrete DAO classes.&lt;/p&gt;

&lt;p&gt;Let&#39;s say you have a simple object called Status which maps to a simple table, and has 2 attributes, an ID and a NAME. Think of it as an object you could use to represent the status of a task. &lt;i&gt;I chose this to illustrate a very basic example here&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;The table for this object would look like this&lt;/p&gt;

&lt;table border=&quot;1&quot;&gt;
&lt;tr&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;th&gt;NAME&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;1&lt;/td&gt;
  &lt;td&gt;Done&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;2&lt;/td&gt;
  &lt;td&gt;In Progress&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;3&lt;/td&gt;
  &lt;td&gt;Not Started&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;And the java class (or DTO object) would look like this (Status.java)&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

public class Status 
{
 private int id;
 private String name;
 
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 
 @Override
 public String toString() {  
  return &quot;[Status] &quot; + &quot;(&quot; + id + &quot;) &quot; + name;
 }
}

&lt;/pre&gt;

&lt;p&gt;Writing the DAO class for the Status object now becomes trivial since you&#39;re inheriting all the default CRUD methods from MyBatisDAO.java defined above.&lt;/p&gt; 

&lt;p&gt;Here&#39;s how the &lt;b&gt;StatusDAO.java&lt;/b&gt; should look:&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

import org.apache.ibatis.session.SqlSessionFactory;

import com.idleworx.mybatisdao.MyBatisDAO;
import com.idleworx.mybatisdao.tests.objects.Status;

public class StatusDAO extends MyBatisDAO&amp;lt;Status,Integer&amp;gt;{
 
 //Don&#39;t forget to define the default custom constructor when implementing a new 
 //child DAO class, and set the class type accordingly 
 public StatusDAO(Class&amp;lt;Status&amp;gt; type,SqlSessionFactory containerSessionFactory) {
  super(type,containerSessionFactory);
 }
 
}

&lt;/pre&gt;

&lt;p&gt;You&#39;ll notice here that all you need to do is call the constructor from the parent MyBatisDAO.java class. Now all the default CRUD methods are available for the StatusDAO.java class.&lt;/p&gt;

&lt;p&gt;You are free of course to add any additional methods as needed here that go beyond the CRUD methods that were defined. For example something like&lt;br&gt;&lt;br&gt;&lt;b&gt; getStatusForBlog(Integer blogId)&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;See the &lt;a href=&quot;https://github.com/idleworx/MyBatisDAOHelper&quot; target=&quot;_blank&quot;&gt;full code example&lt;/a&gt;. &lt;br&gt;&lt;i&gt;Both the MyBatisDAO.java and IParentDAO.java classes are included.&lt;/i&gt;&lt;/p&gt; 

&lt;p&gt;Of course you will still have to define the MyBatis mapper SQL statements for the default CRUD methods defined in MyBatisDAO.java, as well as additional SQLs for other DAO methods you choose to implement. Which brings us to the next step ... &lt;/p&gt;

&lt;h2&gt;Step 4 - Defining the mybatis mapper&lt;/h2&gt;

&lt;p&gt;The last major step in the puzzle, is writing the actual SQL that will implement all the default CRUD methods and any other methods you&#39;ve implemented for the Status object.&lt;/p&gt;

&lt;p&gt;Your code may differ of course, but note the use of the &lt;b&gt;naming conventions&lt;/b&gt; for naming the sql statements which I talked about earlier. &lt;/p&gt;

&lt;p&gt;That is the key to this whole thing, and it will make your life a lot easier when writing other DAOs which extend the MyBatisDAO class.&lt;/p&gt;

&lt;p&gt;Here is an example of how the mapper file for the StatusDAO object would look like. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;StatusMapper.xml&lt;/b&gt;&lt;/p&gt;

&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;

&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; ?&amp;gt;
&amp;lt;!DOCTYPE mapper PUBLIC &amp;quot;-//mybatis.org//DTD Mapper 3.0//EN&amp;quot; &amp;quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&amp;quot;&amp;gt;

&amp;lt;mapper namespace=&amp;quot;mappers&amp;quot;&amp;gt;
 
 &amp;lt;select id=&amp;quot;getStatus&amp;quot; parameterType=&amp;quot;int&amp;quot; resultType=&amp;quot;Status&amp;quot;&amp;gt;
  select 
   status_id as &amp;quot;id&amp;quot;,
   status_name as &amp;quot;name&amp;quot;
  from daohelper.status where status_id = #{id}
 &amp;lt;/select&amp;gt;
 
 &amp;lt;select id=&amp;quot;getAllStatus&amp;quot; parameterType=&amp;quot;int&amp;quot; resultType=&amp;quot;Status&amp;quot;&amp;gt;
  select 
   status_id as &amp;quot;id&amp;quot;,
   status_name as &amp;quot;name&amp;quot;
  from daohelper.status order by status_id
 &amp;lt;/select&amp;gt;
 
 &amp;lt;select id=&amp;quot;getStatusByName&amp;quot; parameterType=&amp;quot;int&amp;quot; resultType=&amp;quot;Status&amp;quot;&amp;gt;
  select 
   status_id as &amp;quot;id&amp;quot;,
   status_name as &amp;quot;name&amp;quot;
  from daohelper.status where status_name = #{name}
 &amp;lt;/select&amp;gt;
 
 &amp;lt;insert id=&amp;quot;createStatus&amp;quot; keyColumn=&amp;quot;status_id&amp;quot; useGeneratedKeys=&amp;quot;true&amp;quot; parameterType=&amp;quot;Status&amp;quot;&amp;gt;
  insert into daohelper.status (status_name)
  values (#{name})  
 &amp;lt;/insert&amp;gt;
 
 &amp;lt;update id=&amp;quot;updateStatus&amp;quot; parameterType=&amp;quot;Status&amp;quot;&amp;gt;
  update daohelper.status set status_name = #{name} where status_id = #{id}  
 &amp;lt;/update&amp;gt;
 
 &amp;lt;delete id=&amp;quot;deleteStatus&amp;quot; parameterType=&amp;quot;int&amp;quot;&amp;gt;
  delete from daohelper.status where status_id = #{id}  
 &amp;lt;/delete&amp;gt; 
 
&amp;lt;/mapper&amp;gt;

&lt;/pre&gt;

&lt;p&gt;Note here the use of the &lt;b&gt;mapper&lt;/b&gt; namespace which is the same as referenced by the MyBatisDAO abstract class. &lt;/p&gt;

&lt;p&gt;It&#39;s used for convenience in this case, and generally you should be able to use multiple mapper files with the same namespace as long as the you don&#39;t have multiple queries with the same id across several xml mapper files (which would be a bad idea anyway)&lt;/p&gt;

&lt;h2&gt;Errors&lt;/h2&gt;

&lt;p&gt;Just a side note on some errors you may encounter.&lt;/p&gt;

&lt;p&gt;If you call one of the default CRUD methods but don&#39;t define the appropriate query in the mapper.xml file, you will get an error like this:&lt;/p&gt;

&lt;pre&gt;
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mappers.getAllFrog
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mappers.getAllFrog
&lt;/pre&gt;


&lt;h2&gt;Wrapping it up&lt;/h2&gt;

&lt;p&gt;By this point I hope you&#39;ve managed to build yourself a small but working DAO implementation based on the MyBatisDAO abstract class. &lt;p&gt;

&lt;p&gt;You can download the &lt;a href=&quot;https://github.com/idleworx/MyBatisDAOHelper&quot; target=&quot;_blank&quot;&gt;full code example&lt;/a&gt; for more a better overview. &lt;/p&gt;

&lt;p&gt;It also contains a jUnit example, the mybatis configuration file (mybatis.config.xml) as well as the simple DDL statments for setting up the MySQL table.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt;If you need to use this from a Servlet or Spring controller, see my other blog post about &lt;a href=&quot;http://blog.idleworx.com/2010/06/initialize-mybatis-servletcontextlisten.html&quot; target=&quot;_blank&quot;&gt;defining a servletcontextlistener&lt;/a&gt;

&lt;h3&gt;Hope you found this useful. Improvements or suggestions are welcome.&lt;/h3&gt;</description><link>http://blog.idleworx.com/2011/09/mybatis-dao-example-code-tutorial.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-965972119421870947</guid><pubDate>Wed, 29 Jun 2011 00:59:00 +0000</pubDate><atom:updated>2017-03-15T21:00:14.741-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>Creating a simple android app with 2 buttons</title><description>&lt;p&gt;How do I build a very simple android app you ask? 
It&#39;s easy, building a basic android application is not that hard. 
Making something really useful, cool and bug free, now that takes a good developer.&lt;/p&gt;

&lt;p&gt;
This is a brief tutorial will show you how to code a very basic two button android application (with a start button and a stop button). &lt;/p&gt;
&lt;p&gt;
You can use this code as an android project template or starting point for simple projects. 
&lt;/p&gt;

&lt;h3&gt;Two Button Application Use Case&lt;/h3&gt;

&lt;p&gt;A simple two button application, can be your starting point for various android projects. It can be useful for example when you have an application that starts and stops a service from the click of a button &lt;a href=&quot;#&quot;&gt;Watch for tutorial on this soon. &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt;This tutorial assumes you have completed the &lt;a href=&quot;http://developer.android.com/resources/tutorials/hello-world.html&quot; target=&quot;_blank&quot;&gt;HelloWorld Tutorial&lt;/a&gt; in the Android docs and you are a little familiar with Eclipse and ADT. The tutorial is aimed at developers who are very new to Android.&lt;/p&gt;

&lt;h3&gt;Creating a two button app&lt;/h3&gt;

&lt;h4&gt;1) Create the project &lt;/h4&gt;

&lt;p&gt;In Eclipse create a new Android project and define the properties as shown below. Feel free to use your own package names.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB1yi-9fKwJQ4qHyt6dS6C1z8GgIofLOa7pYZ0M6Gft7HOsNtiqJ8Fben8UrZyXHAVRkqs6NL8ORNI21WOLXbhh1xEn3snmM7PN6wx7rxDqD20DyjtwJxyXjPkdAOQFBw-MzQo9048Z9fl/s1600/01_create_project.png&quot; imageanchor=&quot;1&quot; style=&quot;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;263&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB1yi-9fKwJQ4qHyt6dS6C1z8GgIofLOa7pYZ0M6Gft7HOsNtiqJ8Fben8UrZyXHAVRkqs6NL8ORNI21WOLXbhh1xEn3snmM7PN6wx7rxDqD20DyjtwJxyXjPkdAOQFBw-MzQo9048Z9fl/s400/01_create_project.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;h4&gt;2) Create a simple layout&lt;/h4&gt;

&lt;p&gt;For our main activity we&#39;re going to define a very basic layout consisting of one TextView and two Buttons (a start button and a stop button).&lt;/p&gt;

&lt;p&gt;Modify your &lt;b&gt;project/res/layout/main.xml&lt;/b&gt; file to this:&lt;/p&gt;

&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;

&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot;
    android:orientation=&amp;quot;vertical&amp;quot;
    android:layout_width=&amp;quot;fill_parent&amp;quot;
    android:layout_height=&amp;quot;fill_parent&amp;quot;
    &amp;gt;
&amp;lt;TextView  
    android:layout_width=&amp;quot;fill_parent&amp;quot; 
    android:layout_height=&amp;quot;wrap_content&amp;quot; 
    android:text=&amp;quot;This is a simple two button app. \r\n \r\n Tell your user what your app does here \r\n \r\n \r\n \r\n&amp;quot;
    android:padding=&amp;quot;10dp&amp;quot;
    android:textColor=&amp;quot;#FFFFFF&amp;quot;
    /&amp;gt;
&amp;lt;Button
 android:id=&amp;quot;@+id/buttonStart&amp;quot;
 android:layout_width=&amp;quot;fill_parent&amp;quot;
 android:layout_height=&amp;quot;wrap_content&amp;quot;
 android:text=&amp;quot;Start&amp;quot;/&amp;gt;
&amp;lt;Button
 android:id=&amp;quot;@+id/buttonStop&amp;quot;
 android:layout_width=&amp;quot;fill_parent&amp;quot;
 android:layout_height=&amp;quot;wrap_content&amp;quot;
 android:text=&amp;quot;Stop&amp;quot;/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;

&lt;/pre&gt;

&lt;p&gt;If you run your project in the emulator it should look like this&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBomKhq_nvz-PlJYjPQHrMh-Hctiefbq1XFTfeGFDtKpFK8hD4_yOdh8I5jrcQBp5DYHcVA7HryVL1RobX2yx-Yqd4UNnjD_eUpWb_YsQFaDoGbQ0D2OTw0iVH6Z3Mq-6nrelrpzDhA5H6/s1600/02_first_peek.png&quot; imageanchor=&quot;1&quot; style=&quot;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBomKhq_nvz-PlJYjPQHrMh-Hctiefbq1XFTfeGFDtKpFK8hD4_yOdh8I5jrcQBp5DYHcVA7HryVL1RobX2yx-Yqd4UNnjD_eUpWb_YsQFaDoGbQ0D2OTw0iVH6Z3Mq-6nrelrpzDhA5H6/s400/02_first_peek.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;h4&gt;3) Adding onClickListeners to the buttons&lt;/h4&gt;

&lt;p&gt;In order for the buttons to actually do something useful, and to provide a template for where you can put future functionality, we&#39;ll need to define onClickListeners for each button.&lt;/p&gt;

&lt;p&gt;Let&#39;s update the TwoButtonApp.java main activiy with the following code:&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

package com.idleworx.android.twobuttonapp;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class TwoButtonApp extends Activity {
    
 private static String logtag = &quot;TwoButtonApp&quot;;//for use as the tag when logging 
  
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button buttonStart = (Button)findViewById(R.id.buttonStart);        
     buttonStart.setOnClickListener(startListener); // Register the onClick listener with the implementation above
      
     Button buttonStop = (Button)findViewById(R.id.buttonStop);        
     buttonStop.setOnClickListener(stopListener); // Register the onClick listener with the implementation above
    }
    
    //Create an anonymous implementation of OnClickListener
    private OnClickListener startListener = new OnClickListener() {
        public void onClick(View v) {
          Log.d(logtag,&quot;onClick() called - start button&quot;);              
          Toast.makeText(TwoButtonApp.this, &quot;The Start button was clicked.&quot;, Toast.LENGTH_LONG).show();
          Log.d(logtag,&quot;onClick() ended - start button&quot;);
        }
    };
    
    // Create an anonymous implementation of OnClickListener
    private OnClickListener stopListener = new OnClickListener() {
        public void onClick(View v) {
         Log.d(logtag,&quot;onClick() called - stop button&quot;); 
         Toast.makeText(TwoButtonApp.this, &quot;The Stop button was clicked.&quot;, Toast.LENGTH_LONG).show();
          Log.d(logtag,&quot;onClick() ended - stop button&quot;);
        } 
    };
    
    
    @Override
 protected void onStart() {//activity is started and visible to the user
  Log.d(logtag,&quot;onStart() called&quot;);
  super.onStart();  
 }
 @Override
 protected void onResume() {//activity was resumed and is visible again
  Log.d(logtag,&quot;onResume() called&quot;);
  super.onResume();
  
 }
 @Override
 protected void onPause() { //device goes to sleep or another activity appears
  Log.d(logtag,&quot;onPause() called&quot;);//another activity is currently running (or user has pressed Home)
  super.onPause();
  
 }
 @Override
 protected void onStop() { //the activity is not visible anymore
  Log.d(logtag,&quot;onStop() called&quot;);
  super.onStop();
  
 }
 @Override
 protected void onDestroy() {//android has killed this activity
   Log.d(logtag,&quot;onDestroy() called&quot;);
   super.onDestroy();
 }
}

&lt;/pre&gt;



&lt;h2&gt;Notes&lt;/h2&gt; 

&lt;ul&gt;
&lt;li&gt;As you can see, each button (or any resource for that matter) can be retrieved by the id was associated with in the layout:
&lt;pre&gt;
@+id/buttonStart 

can be retreived with:

Button buttonStart = (Button)findViewById(R.id.buttonStart);  
&lt;/pre&gt;
&lt;/li&gt;

&lt;li&gt;We have attached two anonymous OnClickListeners() to each of our two buttons&lt;/li&gt;

&lt;li&gt;Each listener displays a simple Toast (a brief message to the user).&lt;/li&gt;

&lt;li&gt;Logging is very important especially during debugging, so make sure you use it where ever you need&lt;/li&gt;

&lt;li&gt;Not the &lt;b&gt;logtag&lt;/b&gt; variable defined in the very top. It&#39;s a quick shortcut to save time when logging statements in your app with the Log.X methods. I usually use the same name as the class name and use the Create Filter option in the LogCat view to filter my code out.&lt;/li&gt;

&lt;li&gt;For easier debugging I&#39;ve added logging of all the other lifecycle methods in the Activity. When you do debugging of your apps it&#39;s very important to understand the &lt;a href=&quot;http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle&quot; target=&quot;_blank&quot;&gt;lifecycle of an android app&lt;/a&gt;, and even more important to see how it&#39;s called in relation to your code.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;So this is it, Introduction to Android 101. You should now have a very basic android app running. &lt;/p&gt;

&lt;p&gt;&lt;i&gt;For reference here is how your &lt;b&gt;AndroidManifest.xml&lt;/b&gt; file should look (you should not have had to modify this file so far if you have followed this tutorial):
&lt;/i&gt;&lt;/p&gt;

&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;

&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&amp;lt;manifest xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot;
      package=&amp;quot;com.idleworx.android.twobuttonapp&amp;quot;
      android:versionCode=&amp;quot;1&amp;quot;
      android:versionName=&amp;quot;1.0&amp;quot;&amp;gt;
    &amp;lt;uses-sdk android:minSdkVersion=&amp;quot;8&amp;quot; /&amp;gt;

    &amp;lt;application android:icon=&amp;quot;@drawable/icon&amp;quot; android:label=&amp;quot;@string/app_name&amp;quot;&amp;gt;
        &amp;lt;activity android:name=&amp;quot;.TwoButtonApp&amp;quot;
                  android:label=&amp;quot;@string/app_name&amp;quot;&amp;gt;
            &amp;lt;intent-filter&amp;gt;
                &amp;lt;action android:name=&amp;quot;android.intent.action.MAIN&amp;quot; /&amp;gt;
                &amp;lt;category android:name=&amp;quot;android.intent.category.LAUNCHER&amp;quot; /&amp;gt;
            &amp;lt;/intent-filter&amp;gt;
        &amp;lt;/activity&amp;gt;

    &amp;lt;/application&amp;gt;
&amp;lt;/manifest&amp;gt;

&lt;/pre&gt;</description><link>http://blog.idleworx.com/2011/06/build-simple-android-app-2-button.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB1yi-9fKwJQ4qHyt6dS6C1z8GgIofLOa7pYZ0M6Gft7HOsNtiqJ8Fben8UrZyXHAVRkqs6NL8ORNI21WOLXbhh1xEn3snmM7PN6wx7rxDqD20DyjtwJxyXjPkdAOQFBw-MzQo9048Z9fl/s72-c/01_create_project.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-6058755465738657137</guid><pubDate>Mon, 20 Jun 2011 02:55:00 +0000</pubDate><atom:updated>2017-03-15T21:00:14.734-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><title>First Android App Goes Live</title><description>&lt;p&gt;I&#39;ve taken an interest in Android App Development a few months ago, and tonight I decided to launch the first android app I created. &lt;/p&gt;

&lt;p&gt;It&#39;s a very simple taxi finder app targeted for people in Bucharest, Romania.&lt;/p&gt;
&lt;p&gt;
If you ever find yourself in Bucharest, Romania and you need a taxi, and you happen to have an android phone, make sure to install this app. It may just be what you need. From the Android market you can search for &quot;vreau taxi&quot; or check out the link below:&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://market.android.com/details?id=com.idleworx.vreautaxi&amp;feature=search_result&quot; target=&quot;_blank&quot;&gt;VreauTaxi&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;The goal of this was to learn the whole process of android app development from top to bottom and I think it went rather well despite a few painful hours dealing with Windows 7 Android USB device installation issues. &lt;/p&gt;

&lt;p&gt;I will write more about Android soon, as some new blog post ideas have been rolling through my head.&lt;/p&gt;</description><link>http://blog.idleworx.com/2011/06/bucharest-romania-taxi-app-android.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-7294767691331236424</guid><pubDate>Wed, 30 Mar 2011 20:33:00 +0000</pubDate><atom:updated>2011-03-30T13:34:44.728-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ruby</category><title>RubyNation 2011</title><description>Going to the RubyNation conference this weekend. Cool stuff.

&lt;a href=&quot;http://www.rubynation.org/&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;http://www.rubynation.org/images/conference/badges/2011/webBadgesConference.png&quot;/&gt;
&lt;/a&gt;</description><link>http://blog.idleworx.com/2011/03/rubynation-2011.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-5814408525884501393</guid><pubDate>Fri, 04 Feb 2011 03:35:00 +0000</pubDate><atom:updated>2017-03-15T21:21:07.965-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">eclipse</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">mybatis</category><category domain="http://www.blogger.com/atom/ns#">mysql</category><category domain="http://www.blogger.com/atom/ns#">tomcat</category><category domain="http://www.blogger.com/atom/ns#">web applications</category><title>The IdleWorx Monster MyBatis Tutorial</title><description>&lt;h2&gt;Building an entire Java web application with MyBatis 3, Tomcat, MySQL and Eclipse (on Windows 7)&lt;/h2&gt;

&lt;p&gt;This is a multi part tutorial which will show you how to build a Servlet/JSP based web application from scratch, using MySQL, Tomcat and MyBatis (the new version of the iBatis framework) on a windows platform using Eclipse.&lt;/p&gt;

&lt;h3&gt;You will make the most of this tutorial if&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;You have built at least a few small webapplications in the past.&lt;/li&gt;
&lt;li&gt;You know how to setup Tomcat 5.x or higher version&lt;/li&gt;
&lt;li&gt;You are somewhat familiar with the Eclipse IDE&lt;/li&gt;
&lt;li&gt;You are familiar with SQL. &lt;/li&gt;
&lt;li&gt;You know how to set-up MySQL on your development box and integrate it with your java web application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Let&#39;s get started&lt;/h3&gt;

&lt;p&gt;To see how Tomcat, MyBatis and MySQL work together we&#39;re going to create a tiny java web application in Eclipse, called &lt;b&gt;ModelingAgency&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;If you don&#39;t want to follow the whole tutorial, you can skip through to the different sections below and pick out the information you need, otherwise continue to &lt;a href=&quot;http://blog.idleworx.com/2011/02/part1-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 1 - The Setup&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Table of Contents&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part1-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 1: The Setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part2-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 2: The ModelingAgency Application&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part3-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 3: Creating the ModelingAgency project in Eclipse&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part4-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 4: Creating a Test Servlet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part5-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 5: Setting up Logging&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part6-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 6: The Java POJO model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part7-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 7: Configuring MyBatis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part8-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 8: Testing MyBatis with jUnit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part9-idleworx-monster-mybatis-tutorial.html&quot; target=&quot;_blank&quot;&gt;Part 9: Creating the DAO Layer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part10-idleworx-monster-mybatis.html&quot; target=&quot;_blank&quot;&gt;Part 10: Initializing MyBatis on Application Startup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part11-idleworx-monster-mybatis.html&quot; target=&quot;_blank&quot;&gt;Part 11: Finalizing the Interface&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;At the end of this tutorial you will hopefully be able to create a basic Java JSP/Servlet based webapp with MyBatis, MySQL and Tomcat in an Eclipse environment.&lt;/p&gt;

&lt;p&gt;You can download a full version of finished ModelingAgency webapp &lt;a href=&quot;https://sites.google.com/site/idleworxblog/modelingagency.war?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;&lt;p&gt;This tutorial took me a long time to write, so if you found it useful in any way, if you found errors with it or you think something is missing, please let me know and I will do my best to improve it.&lt;/p&gt;&lt;/h4&gt;</description><link>http://blog.idleworx.com/2011/02/mybatis-3-tomcat-mysql-eclipse.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-3499171989800946325</guid><pubDate>Fri, 04 Feb 2011 00:32:00 +0000</pubDate><atom:updated>2017-03-15T21:21:07.961-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">gui</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">mybatis</category><category domain="http://www.blogger.com/atom/ns#">mysql</category><category domain="http://www.blogger.com/atom/ns#">tomcat</category><title>Part 11: Finalizing the Interface</title><description>&lt;p&gt;If you have followed this tutorial so far, you will probably remember that in &lt;a href=&quot;http://blog.idleworx.com/2011/02/part2-idleworx-monster-mybatis-tutorial.html&quot;&gt;Part 2&lt;/a&gt; I had shown you how the GUI will look when we&#39;re done. Here it is again:

&lt;br&gt;&lt;br&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06ypfM4jD386O_mnehrdWd_n-3veIoaPKBHodCh4EgRV12CyUgZcPfVf85jFaxWCax-pGlqzGSkHGmMuSHffCmFl4ADIuvBi_f2zVkqji8itj9n0sxIPlHuzfQVy5fCl_4Bsrpf0OcX30/s1600/interface01.gif&quot; imageanchor=&quot;1&quot; &gt;&lt;img border=&quot;0&quot; height=&quot;339&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06ypfM4jD386O_mnehrdWd_n-3veIoaPKBHodCh4EgRV12CyUgZcPfVf85jFaxWCax-pGlqzGSkHGmMuSHffCmFl4ADIuvBi_f2zVkqji8itj9n0sxIPlHuzfQVy5fCl_4Bsrpf0OcX30/s400/interface01.gif&quot; /&gt;&lt;/a&gt;

&lt;/p&gt;

&lt;p&gt;We have put together everything except our interface, so it&#39;s time to modify our &lt;b&gt;index.jsp&lt;/b&gt; to finalize the interface. Here&#39;s how your &lt;b&gt;index.jsp&lt;/b&gt; file should look right now:&lt;/p&gt;

&lt;pre class=&quot;brush: html; wrap-lines:false;&quot;&gt;
&amp;lt;%@ taglib prefix=&amp;quot;c&amp;quot; uri=&amp;quot;http://java.sun.com/jsp/jstl/core&amp;quot; %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD HTML 4.01 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/html4/loose.dtd&amp;quot;&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
 &amp;lt;title&amp;gt;Modeling Agency Index&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h1&amp;gt;The IdleWorx Modeling Agency&amp;lt;/h1&amp;gt;
&amp;lt;hr&amp;gt;

&amp;lt;div style=&amp;quot;width:300px;float:left;&amp;quot;&amp;gt;
 
 &amp;lt;h2&amp;gt;Available Clients&amp;lt;/h2&amp;gt;
 &amp;lt;c:forEach items=&amp;quot;${all_clients}&amp;quot; var=&amp;quot;client&amp;quot;&amp;gt;
  &amp;lt;a href=&amp;quot;client.do?id=${client.id}&amp;quot;&amp;gt;${client.name}&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;
 &amp;lt;/c:forEach&amp;gt; 
&amp;lt;/div&amp;gt;

&amp;lt;div style=&amp;quot;width:300px;float:left;&amp;quot;&amp;gt;
 &amp;lt;h2&amp;gt;Available Models&amp;lt;/h2&amp;gt;
 &amp;lt;c:forEach items=&amp;quot;${all_models}&amp;quot; var=&amp;quot;model&amp;quot;&amp;gt;
  &amp;lt;a href=&amp;quot;model.do?id=${model.id}&amp;quot;&amp;gt;${model.name}&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;
 &amp;lt;/c:forEach&amp;gt; 
&amp;lt;/div&amp;gt;

&amp;lt;div style=&amp;quot;clear:both;&amp;quot;&amp;gt;
 &amp;lt;h2&amp;gt;Bookings&amp;lt;/h2&amp;gt;
 &amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;
 &amp;lt;tr&amp;gt;
  &amp;lt;th&amp;gt;Client&amp;lt;/th&amp;gt;
  &amp;lt;th&amp;gt;Model&amp;lt;/th&amp;gt;
  &amp;lt;th&amp;gt;Time&amp;lt;/th&amp;gt;
  &amp;lt;th&amp;gt;Place&amp;lt;/th&amp;gt;
 &amp;lt;/tr&amp;gt;
 &amp;lt;c:forEach items=&amp;quot;${all_bookings}&amp;quot; var=&amp;quot;booking&amp;quot;&amp;gt;
 &amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;${booking.client.name}&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;${booking.model.name}&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;${booking.time}&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;${booking.location}&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;
 &amp;lt;/tr&amp;gt;
 &amp;lt;/c:forEach&amp;gt; 
 &amp;lt;/table&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Open up: &lt;a href=&quot;http://localhost:8080/ModelingAgency/test.do&quot; target=&quot;_blank&quot;&gt;http://localhost:8080/ModelingAgency/test.do&lt;/a&gt;. You should now have an interface very similar to the image above.&lt;/p&gt;

&lt;p&gt;You&#39;ll notice I used the JSTL and EL libraries to nicely write our output (please don&#39;t use scriptlets in your JSP classes).&lt;/p&gt;

&lt;p&gt;Also if you haven&#39;t noticed so far, in your ModelingAgency web application folder, you should have a file called &lt;b&gt;sql.log&lt;/b&gt; wich has logged all of the SQL statements that MyBatis generated. You may find it useful when debugging your MyBatis apps&lt;/p&gt;

&lt;h2&gt;Congrats&lt;/h2&gt;

&lt;p&gt;If you got this far, I hope you now feel more comfortable about MyBatis,Tomcat and MySQL. You should now have all the basics to get a very simple app started in Eclipse using these technologies.&lt;/p&gt;

&lt;p&gt;You can download a full version of the app &lt;a href=&quot;https://sites.google.com/site/idleworxblog/modelingagency.war?attredirects=0&amp;d=1&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;&lt;p&gt;This tutorial took me a long time to write, so if you found it useful in any way, if you found errors with it or you think something is missing, please let me know and I will do my best to improve it.&lt;/p&gt;&lt;/h4&gt;

&lt;p&gt;Go back to the &lt;a href=&quot;http://blog.idleworx.com/2011/02/mybatis-3-tomcat-mysql-eclipse.html&quot;&gt;IdleWorx Monster MyBatis Tutorial&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.idleworx.com/2011/02/part11-idleworx-monster-mybatis.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06ypfM4jD386O_mnehrdWd_n-3veIoaPKBHodCh4EgRV12CyUgZcPfVf85jFaxWCax-pGlqzGSkHGmMuSHffCmFl4ADIuvBi_f2zVkqji8itj9n0sxIPlHuzfQVy5fCl_4Bsrpf0OcX30/s72-c/interface01.gif" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-4890871238098698640</guid><pubDate>Fri, 04 Feb 2011 00:30:00 +0000</pubDate><atom:updated>2017-03-19T20:28:36.818-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">mybatis</category><category domain="http://www.blogger.com/atom/ns#">mysql</category><category domain="http://www.blogger.com/atom/ns#">tomcat</category><title>Part 10: Initializing MyBatis on Application Startup</title><description>&lt;p&gt;If you&#39;ve been following &lt;a href=&quot;http://blog.idleworx.com/2011/02/part9-idleworx-monster-mybatis-tutorial.html&quot;&gt;Part 9&lt;/a&gt; of this tutorial, we now need to make sure our application has an sqlSessionVariable available ready to go when the TestServlet is invoked.&lt;/p&gt;

&lt;p&gt;I had recently written a more detailed article about how to initialize MyBatis when a web application starts up. You can read that &lt;a href=&quot;http://blog.idleworx.com/2010/06/initialize-mybatis-servletcontextlisten.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;For this part of the tutorial, I&#39;m just going to summarize what you need to do to get MyBatis to automatically initialize when the ModelingAgency webapp starts.&lt;/p&gt;  

&lt;h2&gt;Setting up a ServletContextListener&lt;/h2&gt;

&lt;p&gt;A ServletContextListener is useful when you want to do something when a java application starts up, more specifically, when a ServletContext is initalized.&lt;/p&gt;

&lt;p&gt;In our case, we&#39;re going to use a ServletContextListener to set a MyBatis SqlSessionan application scoped varible. This will allow us to instantiate our ModelingAgencyDAO object from our TestServlet. Here&#39;s how to do it: &lt;/p&gt;

&lt;h3&gt;1) Register the listener in web.xml&lt;/h3&gt;

&lt;p&gt;Add the following code to &lt;b&gt;web.xml&lt;/b&gt;&lt;/p&gt;

&lt;pre class=&quot;brush: xml; wrap-lines:false;&quot;&gt;
&amp;lt;listener&amp;gt;
   &amp;lt;listener-class&amp;gt;
  com.modelingagency.listeners.CustomServletContextListener
   &amp;lt;/listener-class&amp;gt;
 &amp;lt;/listener&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;2) Create the Listener class&lt;/h3&gt;

&lt;p&gt;Create the class &lt;b&gt;CustomServletContextListener.java&lt;/b&gt; under the &lt;b&gt;com.modelingagency.listeners&lt;/b&gt; package:&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

package com.modelingagency.listeners;
 
import java.io.Reader;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
 
public class CustomServletContextListener implements ServletContextListener
{
 public void contextInitialized(ServletContextEvent event)
 {  
  ServletContext ctx = event.getServletContext(); 
        
     String resource = &quot;mybatis.config.xml&quot;;
     try{      
      Reader reader = Resources.getResourceAsReader(resource);     
      SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); //this will load the default environment configured in mybatis.config.xml
      ctx.setAttribute(&quot;sqlSessionFactory&quot;, sqlSessionFactory); //set the sqlSessionFactory as an application scoped variable
     }
     catch(Exception e){
      System.out.println(&quot;FATAL ERROR: myBatis could not be initialized&quot;);
      System.exit(1);
     }    
 }
 
 @Override
 public void contextDestroyed(ServletContextEvent event){
   //nothing to do here right now
 }
}

&lt;/pre&gt;

&lt;p&gt;If everything went well so far, you should be able to run the application again. Going to &lt;a href=&quot;http://localhost:8080/ModelingAgency/test.do&quot; target=&quot;_blank&quot;&gt;http://localhost:8080/ModelingAgency/test.do&lt;/a&gt; however will show the same things as before. So we need to finalize our interface. &lt;/p&gt;

&lt;h4&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part11-idleworx-monster-mybatis.html&quot;&gt;Part 11: Finalizing the Interface&lt;/a&gt;&lt;/h4&gt;</description><link>http://blog.idleworx.com/2011/02/part10-idleworx-monster-mybatis.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4368777317649012081.post-164456841571150782</guid><pubDate>Fri, 04 Feb 2011 00:26:00 +0000</pubDate><atom:updated>2017-03-19T20:28:36.803-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dao</category><category domain="http://www.blogger.com/atom/ns#">migrated</category><category domain="http://www.blogger.com/atom/ns#">mybatis</category><category domain="http://www.blogger.com/atom/ns#">mysql</category><category domain="http://www.blogger.com/atom/ns#">tomcat</category><title>Part 9: Creating the DAO Layer</title><description>&lt;p&gt;
Now that both our Java Data Model and our Database Model are connected through a MyBatis mapper file, we will add a Data Access Object class so we can abstract the calling of SQL statements, and keep our servlet clean of database related code. &lt;/p&gt;

&lt;p&gt;
I know it&#39;s not a &#39;pure&#39; implementation of the DAO pattern however it serves the main purpose of decoupling servlet code from database related code.&lt;/p&gt;

&lt;p&gt;If you want to see a better way to integrate MyBatis and basic DAO classes, check out my other blog post &lt;a href=&quot;http://blog.idleworx.com/2011/09/mybatis-dao-example-code-tutorial.html&quot;&gt;MyBatis DAO Example Code Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;ModelingAgencyDAO.java&lt;/h2&gt;

&lt;p&gt;ModelingAgencyDAO is going to be a Java class which encapsulates all the &#39;logical&#39; database functionality we need, such as getting a list of all clients, models and bookings in our database. It will accomplish this by using the MyBatis framework.&lt;/p&gt;

&lt;p&gt;For now, create the file &lt;b&gt;ModelingAgencyDAO.java&lt;/b&gt; under the &lt;b&gt;com.modelingagency.db&lt;/b&gt; package, with the following content:&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

package com.modelingagency.db;

import java.util.ArrayList;

import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;

import com.modelingagency.objects.Booking;
import com.modelingagency.objects.Client;
import com.modelingagency.objects.Model;

public class ModelingAgencyDAO {

 private SqlSessionFactory sf;
 
 //constructor will receive a myBatis sessionFactory object
 public ModelingAgencyDAO(SqlSessionFactory containerSessionFactory) {
  if(containerSessionFactory==null)
   System.err.println(&amp;quot;Error: could not load myBatis sessionFactory&amp;quot;);  
  sf = containerSessionFactory;
 }
   
 public ArrayList&amp;lt;Client&amp;gt; getClients() throws PersistenceException{
    
  SqlSession session = sf.openSession();
  try
  {   
   ArrayList&amp;lt;Client&amp;gt; clients = (ArrayList&amp;lt;Client&amp;gt;)session.selectList(&amp;quot;com.modelingagency.objects.SimpleMappers.allClients&amp;quot;);    
   return clients;  
  }
  finally
  {
   session.close();
  }
  
 }
  
 public ArrayList&amp;lt;Model&amp;gt; getModels() throws PersistenceException{
    
  SqlSession session = sf.openSession();
  try
  {   
   ArrayList&amp;lt;Model&amp;gt; models = (ArrayList&amp;lt;Model&amp;gt;)session.selectList(&amp;quot;com.modelingagency.objects.SimpleMappers.allModels&amp;quot;);    
   return models;
  }
  finally
  {
   session.close();
  }
  
 }
 
 @Test
 public ArrayList&amp;lt;Booking&amp;gt; getBookings() throws PersistenceException{
    
  SqlSession session = sf.openSession();
  try
  {   
   ArrayList&amp;lt;Booking&amp;gt; bookings = (ArrayList&amp;lt;Booking&amp;gt;)session.selectList(&amp;quot;com.modelingagency.objects.SimpleMappers.allBookings&amp;quot;);    
   return bookings;   
  }
  finally
  {
   session.close();
  }
  
 }
 
}

&lt;/pre&gt;

&lt;p&gt;You will notice the methods in this DAO class are very similar to the ones we defined in the MyBatisTest class in &lt;a href=&quot;http://blog.idleworx.com/2011/02/part8-idleworx-monster-mybatis-tutorial.html&quot;&gt;Part 8&lt;/a&gt;. It&#39;s a good idea to have a test case setup for your DAO classes.&lt;/P&gt;

&lt;p&gt;Now in order to use the DAO from a servlet, all you have to do is create a new object and pass in a MyBatis SqlSessionFactory through the constructor. &lt;/p&gt;

&lt;p&gt;Let&#39;s modify our TestServlet so we can make use of our DAO class to retreive a list of all clients, a list of all models, and a list of all bookings. Your TestServlet.java class should now look like this:&lt;/p&gt;

&lt;pre class=&quot;brush: java; wrap-lines:false;&quot;&gt;

package com.modelingagency.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.modelingagency.db.ModelingAgencyDAO;
import com.modelingagency.objects.*;

public class TestServlet  extends HttpServlet{
 
 private static Logger log = LoggerFactory.getLogger(TestServlet.class);
 
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
 {
  HttpSession session = request.getSession();   
  ServletContext sc = getServletContext();
  
  SqlSessionFactory sf = (SqlSessionFactory)getServletContext().getAttribute(&amp;quot;sqlSessionFactory&amp;quot;);
  ModelingAgencyDAO dao = new ModelingAgencyDAO(sf);
  
  try
  {
   ArrayList&amp;lt;Client&amp;gt; clients = dao.getClients();    
   ArrayList&amp;lt;Model&amp;gt; models = dao.getModels();    
   ArrayList&amp;lt;Booking&amp;gt; bookings = dao.getBookings();    
   
   request.setAttribute(&amp;quot;all_clients&amp;quot;, clients); 
   request.setAttribute(&amp;quot;all_models&amp;quot;, models);
   request.setAttribute(&amp;quot;all_bookings&amp;quot;, bookings);
       
  }
  catch(PersistenceException p)
  {
   p.printStackTrace();  
  }
  finally
  {
   request.setAttribute(&amp;quot;message&amp;quot;,&amp;quot;Welcome to the modeling agency MyBatis tutorial&amp;quot;);
   log.info(&amp;quot;The message attribute has been set&amp;quot;);
  } 
                
  RequestDispatcher view = request.getRequestDispatcher(&amp;quot;index.jsp&amp;quot;);
  view.forward(request, response);
 }
 
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  doPost(request,response);
 }
 
}

&lt;/pre&gt;

&lt;p&gt;But before you can run the web application, you&#39;ll need to make sure that MyBatis has been initalized and available to the ModelingAgency app. &lt;h4&gt;&lt;a href=&quot;http://blog.idleworx.com/2011/02/part10-idleworx-monster-mybatis.html&quot;&gt;Part 10: Initializing MyBatis on application startup&lt;/a&gt;&lt;/h4&gt;</description><link>http://blog.idleworx.com/2011/02/part9-idleworx-monster-mybatis-tutorial.html</link><author>noreply@blogger.com (Unknown)</author></item></channel></rss>