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

<channel>
	<title>Adams Bros Blog &#187; Java</title>
	<atom:link href="http://blog.adamsbros.org/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adamsbros.org</link>
	<description></description>
	<lastBuildDate>Sun, 01 Jan 2012 03:28:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Send Email in your Android Application</title>
		<link>http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/</link>
		<comments>http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 21:48:59 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=416</guid>
		<description><![CDATA[I've seen a lot of examples of how to send email from an android application.  All of them result in applications coming up in a chooser list that are not appropriate for sending email.  In this post, I'll described the various solutions I found, and the solution that brings up only email clients.

If you want [...]]]></description>
			<content:encoded><![CDATA[<p>I've seen a lot of examples of how to send email from an android application.  All of them result in applications coming up in a chooser list that are not appropriate for sending email.  In this post, I'll described the various solutions I found, and the solution that brings up only email clients.<br />
<span id="more-416"></span></p>
<p>If you want to skip the junk, and go straight to the solution, go to the last two code snippets at the end.</p>
<p>One variation, from stack overflow, goes something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Intent intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_SEND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">setType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_EMAIL</span>  , <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;recipient@example.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_SUBJECT</span>, <span style="color: #0000ff;">&quot;subject of email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">EXTRA_TEXT</span>   , <span style="color: #0000ff;">&quot;body of email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
startActivity<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">createChooser</span><span style="color: #009900;">&#40;</span>intent, <span style="color: #0000ff;">&quot;Send mail...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The reason this doesn't work properly, is because it brings up pretty much any app that can handle <strong>text/plain</strong> content. To expect a user to send an email with bluetooth, or wifi, or evernote, is simply not appropriate.  So, if your intention is to have them send an actual email, as opposed to sharing content in some other way, then this won't work for you.</p>
<p>Another variation from stack overflow, is to replace the mime-type of <strong>text/plain</strong> with <strong>message/rfc822</strong>.  This results in a list of applications that can handle "email message" content.  As a result, if you have ever-note installed, it comes up in the list as well.  It will happily store your complete RFC822 email message for you.  However, this is a hack, and is totally not appropriate.  That mime type implies that you have already constructed a complete and valid RFC822 email message, including headers and what not.</p>
<p>Finally, I was able to find an example on the IT Wizard website, that shows the almost proper way of doing this, using the <strong>mailto</strong> URI handling.  Theoretically, only valid email applications will ever come up in this list.  It goes like this...</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Intent intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_SENDTO</span>, Uri.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mailto:someone@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;subject&quot;</span>, <span style="color: #0000ff;">&quot;my subject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">putExtra</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;body&quot;</span>, <span style="color: #0000ff;">&quot;my message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
startActivity<span style="color: #009900;">&#40;</span>intent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Unfortunately, that only works with gmail on my phone.  So, I revised it to include everything inside the mailto url.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Intent intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_SENDTO</span>, Uri.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mailto:someone@example.com?subject=&quot;</span> <span style="color: #339933;">+</span>
    Uri.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my subject&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>  <span style="color: #0000ff;">&quot;&amp;body=&quot;</span> <span style="color: #339933;">+</span>
    Uri.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;My big long body with spaces, new lines, and all sorts of invalid URI characters&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
startActivity<span style="color: #009900;">&#40;</span>intent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now the only activities that come up are email apps. <img src='http://blog.adamsbros.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   Now, if you want the complete list of email applications to always come up for the user, whether they've chosen a "default" email app or not, then you need to start the activity like this...</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">startActivity<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">createChooser</span><span style="color: #009900;">&#40;</span>intent, <span style="color: #0000ff;">&quot;your chooser title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I do not know how to attach files to an email, using this method; in fact I do not think it is possible, seeing the <strong>mailto:</strong> URL scheme is pretty limited.  So, unfortunately, if you want to attach files, you're going to have to use one of the other methods, with the <strong>EXTRA_STREAM</strong> option to <strong>putExtra()</strong> and file URI pointing to a file on your android device.  As a result, you'll just have to live with some non-email related applications coming up.</p>
<p>If someone has a way of making sure ONLY email apps come up, using the other methods, I'd sure like to hear about it.  Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conversion to Dalvik format failed with error</title>
		<link>http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/</link>
		<comments>http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 05:28:58 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=411</guid>
		<description><![CDATA[I went looking, and looking, and looking, for a solution to this problem.  None of them seemed to fit the bill.  I tried...

updating proguard
not using libraries I shouldn't be
re-importing the project
removing duplicate android jars
removing all android jars
a host of other "suggestions" from Eclipse Android users


Not one of the ones I found worked.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I went looking, and looking, and looking, for a solution to this problem.  None of them seemed to fit the bill.  I tried...</p>
<ol>
<li>updating proguard</li>
<li>not using libraries I shouldn't be</li>
<li>re-importing the project</li>
<li>removing duplicate android jars</li>
<li>removing all android jars</li>
<li>a host of other "suggestions" from Eclipse Android users</li>
</ol>
<p><span id="more-411"></span></p>
<p>Not one of the ones I found worked.  I suddenly right clicked the project, and happened to see a menu called "<strong>Android Tools</strong>".  I wasn't thinking it would do anything for my predicament, but was curious what was under it.  I then saw, and clicked, the item called "<strong>Fix Project Properties</strong>", and voilà, the error disappeared.</p>
<p>Go figure, an Eclipse option to fix a problem that Eclipse caused.  KEWL!</p>
<p>Hope this helps someone through their pain.</p>
<p>IntelliJ folks, <strong>PLEASE</strong> add GUI support for android, so that I can ditch this piece of junk Java IDE called Eclipse.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Android Hello World Tutorial Video – Part 3</title>
		<link>http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/</link>
		<comments>http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 03:01:11 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=394</guid>
		<description><![CDATA[In third part of the android hello world video, we explain the different components of the application, and why things are done in a certain way.  This video is a bit raw.  However, rather than editing the videos, I'm going to try and improve my presentation skills as I go.
Before we get started, the code [...]]]></description>
			<content:encoded><![CDATA[<p>In third part of the android hello world video, we explain the different components of the application, and why things are done in a certain way.  This video is a bit raw.  However, rather than editing the videos, I'm going to try and improve my presentation skills as I go.</p>
<p><span id="more-394"></span>Before we get started, the code for part 3 is located on <a href="https://github.com/TrentonAdams/HelloAndroid">github</a> under the tag "<a href="https://github.com/TrentonAdams/HelloAndroid/tree/part3">part3</a>".  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>TrentonAdams<span style="color: #000000; font-weight: bold;">/</span>HelloAndroid.git HelloAndroid
<span style="color: #7a0874; font-weight: bold;">cd</span> HelloAndroid
git checkout part3</pre></div></div>

<p>In this video, we will</p>
<ol>
<li>explain the various sections of code</li>
<li>explain the semantics of the android <strong>R</strong> class for referencing resources</li>
<li>explain the use of localized resource files</li>
</ol>
<p>We have one new screenshot from this video in the series.  It is the French version of the application.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2011/07/bonjourandroid-dialogue.png"></a><a href="http://blog.adamsbros.org/wp-content/uploads/2011/07/bonjourandroid-dialogue.png"><img class="alignnone size-medium wp-image-397" title="Bonjour Android Dialogue" src="http://blog.adamsbros.org/wp-content/uploads/2011/07/bonjourandroid-dialogue-180x300.png" alt="" width="180" height="300" /></a></p>
<p>If this video fails to play, please check back later, it may still be processing.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/Vfx-wo5XKdk" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/Vfx-wo5XKdk"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eclipse Android Hello World Tutorial Video – Part 2</title>
		<link>http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/</link>
		<comments>http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 01:05:37 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=368</guid>
		<description><![CDATA[Part 3 - Code Explained
Okay, I've finished another android development demo video.  Sorry it took so long, I got really busy with a new computer and what not, and life in general.  In the next video in this series, I will explain the details of the hello android application.  So, if you do not understand [...]]]></description>
			<content:encoded><![CDATA[<p><a style="float: right;" href="http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/">Part 3 - Code Explained</a></p>
<p>Okay, I've finished another android development demo video.  Sorry it took so long, I got really busy with a new computer and what not, and life in general.  In the next video in this series, I will explain the details of the hello android application.  So, if you do not understand some of what is happening, stay tuned for the next video in the series.</p>
<p><span id="more-368"></span></p>
<p>Before we get started, the code for part 2 is located on <a href="https://github.com/TrentonAdams/HelloAndroid">github</a> under the tag "<a href="https://github.com/TrentonAdams/HelloAndroid/tree/part2">part2</a>".  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>TrentonAdams<span style="color: #000000; font-weight: bold;">/</span>HelloAndroid.git HelloAndroid
<span style="color: #7a0874; font-weight: bold;">cd</span> HelloAndroid
git checkout part2</pre></div></div>

<p>In this video, we do the following...</p>
<ol>
<li> an actual android application with a button that opens a dialog box. The dialog box has a Okay/Cancel button.</li>
<li>Handling and implementing events
<ol>
<li>onCreateDialog(int) - when a dialog is requested to be created in this activity, this method is called</li>
<li>onClick(View arg0) - we tied the click event from the button to our activity rather than making a custom class for it</li>
</ol>
</li>
<li>log debug information to the android log</li>
<li>use logcat to see the debug information</li>
</ol>
<p>Below are the two screens that you will see in this application.</p>
<div id="attachment_370" class="wp-caption alignnone" style="width: 190px"><a href="http://blog.adamsbros.org/wp-content/uploads/2011/07/helloandroid.png"><img class="size-medium wp-image-370" title="Hello Android Screenshot" src="http://blog.adamsbros.org/wp-content/uploads/2011/07/helloandroid-180x300.png" alt="" width="180" height="300" /></a><p class="wp-caption-text">Hello Android Screenshot</p></div>
<div id="attachment_371" class="wp-caption alignnone" style="width: 190px"><a href="http://blog.adamsbros.org/wp-content/uploads/2011/07/helloandroid-dialog.png"><img class="size-medium wp-image-371" title="Hello Android Okay/Cancel Dialog" src="http://blog.adamsbros.org/wp-content/uploads/2011/07/helloandroid-dialog-180x300.png" alt="" width="180" height="300" /></a><p class="wp-caption-text">Hello Android Okay/Cancel Dialog</p></div>
<p><strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/-9TRZMQm8-8" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/-9TRZMQm8-8"></embed></object><br />
</strong></p>
<p>This android demo was created using a software package under Linux   called "recordMyDesktop".  It's terribly slow for encoding the video, which it does after the video has been recorded.  I think it's recording my whole screen as a series of screenshots, which is probably what takes it so long.  I used it from the command line, as I have   not yet attempted to use a GUI tool with it.  I found that I  basically  required 240 fps, because it did not capture all of my  selections if I  did not use a high frame rate.  This time I decreased the quality and the bitrate, as it did not seem to make a huge impact on quality.</p>
<p>recordmydesktop --pause-shortcut Control+Shift+P --fps 240 --v_quality 30 --v_bitrate 400 -o ~/Videos/newvideo</p>
<p>This is based in part on the Android Hello World documentation at   http://developer.android.com/resources/tutorials/hello-world.html</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eclipse Android Hello World Tutorial Video &#8211; Part 1</title>
		<link>http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/</link>
		<comments>http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 06:22:25 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=341</guid>
		<description><![CDATA[Part 2
My intention is to make all of my android videos as simple as possible, and as short as possible.  That way you can learn what you need to, and get on with it.
This is a quick demo on how to get started on developing for Android.  It is "hopefully" the first in a [...]]]></description>
			<content:encoded><![CDATA[<p><a style="float: right;" href="http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/">Part 2</a></p>
<p>My intention is to make all of my android videos as simple as possible, and as short as possible.  That way you can learn what you need to, and get on with it.</p>
<p>This is a quick demo on how to get started on developing for Android.  It is "hopefully" the first in a serious of android demo videos that I will be creating.  I am mainly creating them for myself, so as to become familiar with basic android development tasks, and also to play with recording sessions; I too am a newbie to Android development.  I am putting them on YouTube in case anyone else may find them valuable; perhaps for their simplicity.  I hope you enjoy.<br />
<span id="more-341"></span></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/TFPyL0gSP5E" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/TFPyL0gSP5E"></embed></object></p>
<p>This android demo was created using a software package under Linux  called "recordMyDesktop".  I used it from the command line, as I have  not yet attempted to use a GUI tool with it.  I found that I  basically required 60 fps, because it did not capture all of my  selections if I did not use a high frame rate.</p>
<p>recordmydesktop --fps 60 --v_bitrate 3500 -o helloandroid.ogv</p>
<p>This is based in part on the Android Hello World documentation at  http://developer.android.com/resources/tutorials/hello-world.html</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java LDAP Persistence API</title>
		<link>http://blog.adamsbros.org/2011/01/01/ldap-persistence-api/</link>
		<comments>http://blog.adamsbros.org/2011/01/01/ldap-persistence-api/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 22:20:01 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=302</guid>
		<description><![CDATA[I've started a project called LDAP Persistence API for Java, or LPA for short.  It is a Java framework for interacting with LDAP entries using pure Java objects.  It is based on Java annotations.
It is no were near to being complete, but the query functionality is working.  I still have a lot [...]]]></description>
			<content:encoded><![CDATA[<p>I've started a project called LDAP Persistence API for Java, or LPA for short.  It is a Java framework for interacting with LDAP entries using pure Java objects.  It is based on Java annotations.</p>
<p>It is no were near to being complete, but the query functionality is working.  I still have a lot of work to do, in order to make it be able to persist existing annotated Java objects to LDAP.  I'm likely to create some sort of intermediate step, until I can finish that.<span id="more-302"></span></p>
<p>A quick example of how easy it is to use, pulled directly from one of our Classes and unit tests.  The following class, is a portion of our LdapOrganization Class, showing how simple it is to annotate the class to be automatically loaded from LDAP.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This file is part of the Ldap Persistence API (LPA).
 *
 * Copyright Trenton D. Adams
 *
 * LPA is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * LPA is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with LPA.  If not, see .
 *
 * See the COPYING file for more information.
 */</span>
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">ca.tnt.ldaputils.impl</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ca.tnt.ldaputils.ILdapGroup</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ca.tnt.ldaputils.ILdapOrganization</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ca.tnt.ldaputils.annotations.LdapAttribute</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ca.tnt.ldaputils.annotations.LdapEntity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ca.tnt.ldaputils.annotations.TypeHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.lang.builder.CompareToBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.lang.builder.EqualsBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.lang.builder.HashCodeBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Implements an LDAP organization object.
 *
 * Created :  16-Apr-2006 10:25:36 PM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 *
 * @author Trenton D. Adams
 */</span>
@LdapEntity<span style="color: #009900;">&#40;</span>requiredObjectClasses <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;organization&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LdapOrganization <span style="color: #000000; font-weight: bold;">extends</span> LdapEntry
    <span style="color: #000000; font-weight: bold;">implements</span> ILdapOrganization, <span style="color: #003399;">Comparable</span>, TypeHandler
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>
        LdapOrganization.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;businessCategory&quot;</span>, aggregateClass <span style="color: #339933;">=</span> LdapGroup.<span style="color: #000000; font-weight: bold;">class</span>,
        referencedDNMethod <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;getCategoryDN&quot;</span>
        <span style="color: #666666; font-style: italic;">/*&quot;cn=?,ou=bus-categories,dc=example,dc=com&quot;*/</span>
    <span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">SortedMap</span> businessCategories<span style="color: #339933;">;</span>
&nbsp;
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;telephoneNumber&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> telephoneNumber<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;facsimileTelephoneNumber&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> facsimileTelephoneNumber<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;street&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> street<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;postOfficeBox&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> postOfficeBox<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;postalAddress&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> postalAddress<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;postalCode&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> postalCode<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;l&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> locality<span style="color: #339933;">;</span>
    @LdapAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;o&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> organization<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// ... getters, setters, etc.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The following is a unit test, testing the above class.  Take special note of how it is a single method call, to retrieve your entry, simply by calling manager.find(Class theClass, ldapName).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">private</span> LdapManager manager<span style="color: #339933;">;</span>
&nbsp;
        manager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LdapManager<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span>,
            <span style="color: #0000ff;">&quot;uid=admin,ou=system&quot;</span>, <span style="color: #0000ff;">&quot;secret&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">final</span> LdapName ldapName <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LdapName<span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">&quot;o=Pulp Mill.,ou=businesses,dc=example,dc=com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">final</span> LdapOrganization ldapEntry <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LdapOrganization<span style="color: #009900;">&#41;</span> manager.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>
            LdapOrganization.<span style="color: #000000; font-weight: bold;">class</span>, ldapName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">SortedMap</span> categories <span style="color: #339933;">=</span>
            ldapEntry.<span style="color: #006633;">getBusinessCategories</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertNotNull</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Manufacturing category does not exist&quot;</span>,
            categories.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Manufacturing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertNotNull</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pulp &amp; Paper Products category does not exist&quot;</span>,
            categories.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pulp &amp; Paper Products&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pulp Mill business categories&quot;</span>, <span style="color: #cc66cc;">2</span>,
            categories.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Organization should be Pulp Mill&quot;</span>,
            <span style="color: #0000ff;">&quot;Pulp Mill.&quot;</span>, ldapEntry.<span style="color: #006633;">getOrganization</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We have a good start on the project, but we have a very long way to go.  If anyone is interested in helping out with the framework, please wander over to<a title="LDAP Persistence API" href="http://trentonadams.github.com/lpa/"> github, and check it out</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2011/01/01/ldap-persistence-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Array Reflection</title>
		<link>http://blog.adamsbros.org/2010/12/08/java-array-reflection/</link>
		<comments>http://blog.adamsbros.org/2010/12/08/java-array-reflection/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 03:32:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=292</guid>
		<description><![CDATA[In this article we talk about reflection with arrays in Java.  Java array reflection is not difficult, but it can be trying to figure it out without a good example.  Ultimately, what I needed was a way of injecting information into an array field.  Of course, you need to inject the same [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we talk about reflection with arrays in Java.  Java array reflection is not difficult, but it can be trying to figure it out without a good example.  Ultimately, what I needed was a way of injecting information into an array field.  Of course, you need to inject the same "type" of array as the field is.  That is what can be difficult to figure out, if you've never done it before.</p>
<p>In this example, I am using Java 1.6.  I won't bother determining what is, or is not supported in prior versions of the Java language.</p>
<p><span id="more-292"></span><br />
I may at some point create a "working" example, rather than a code snippet.  But, if you've done reflection before, you should get the gist of what I'm doing here.</p>
<p>Basically, all we do is</p>
<ol>
<li> create a java.util.List object</li>
<li>create a new array of the same type as the field we're reflecting</li>
<li>ask the List object to insert all it's elements into the new array</li>
<li>assign the array to the field.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">            <span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> refType <span style="color: #339933;">=</span> field.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>refType.<span style="color: #006633;">isArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// handle multiple ldap values</span>
                <span style="color: #000000; font-weight: bold;">final</span> NamingEnumeration<span style="color: #339933;">&lt;?&gt;</span> values <span style="color: #339933;">=</span> attribute.<span style="color: #006633;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span> ldapEntities <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>values.<span style="color: #006633;">hasMore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// iterate through all ldap attributes</span>
                    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> valueObject <span style="color: #339933;">=</span> values.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    ldapEntities.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>getReferencedDN<span style="color: #009900;">&#40;</span>agg.<span style="color: #006633;">aggregateClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
                        dnReference, valueObject<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #666666; font-style: italic;">// convert to the array type used in the field</span>
                <span style="color: #666666; font-style: italic;">// create an array the same size as the ldapEntities List</span>
                <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> refArray <span style="color: #339933;">=</span> <span style="color: #003399;">Array</span>.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>
                    refType.<span style="color: #006633;">getComponentType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, ldapEntities.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">// ask List implementation to copy all elements to the new array</span>
                <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> aggregatedList <span style="color: #339933;">=</span> ldapEntities.<span style="color: #006633;">toArray</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> refArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                field.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>object, aggregatedList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/12/08/java-array-reflection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What is JAXB and JAXB Example Code</title>
		<link>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/</link>
		<comments>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 03:12:28 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=200</guid>
		<description><![CDATA[I thought it may be nice for those googlers that want to know about JAXB, to have a quick working example to use.  So, that is the purpose of this post.
First off, what is JAXB?  Well, simply put, JAXB is for converting Java objects to XML or from XML to Java objects.  With the advent [...]]]></description>
			<content:encoded><![CDATA[<p>I thought it may be nice for those <a title="Googlers" href="http://www.google.com">googlers</a> that want to know about JAXB, to have a quick working example to use.  So, that is the purpose of this post.</p>
<p><span id="more-200"></span>First off, what is JAXB?  Well, simply put, JAXB is for converting Java objects to XML or from XML to Java objects.  With the advent of Java 1.5, and annotations, this becomes extremely simple.</p>
<p>Download <a title="JAXB Download" href="http://www.google.com/search?q=jaxb+download">JAXB</a>, dependencies to your local computer, and put them in a folder called "libs". The dependencies JARs I have are...</p>
<ul>
<li>activation-1.1.jar</li>
<li>jaxb-api-2.0.jar</li>
<li>jaxb-impl-2.0.5.jar</li>
<li>jsr173_api-1.0.jar</li>
</ul>
<p>Copy the following Java source code to Employee.java, and proceed with the instructions below</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.JAXBContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.JAXBException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.annotation.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.StringReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.StringWriter</span><span style="color: #339933;">;</span>
&nbsp;
@XmlRootElement<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;employee&quot;</span><span style="color: #009900;">&#41;</span>
@XmlAccessorType<span style="color: #009900;">&#40;</span>XmlAccessType.<span style="color: #006633;">FIELD</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Employee
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JAXBException
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> Employee john <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setMiddleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Robert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setLastName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// write it out as XML</span>
        <span style="color: #000000; font-weight: bold;">final</span> JAXBContext jaxbContext <span style="color: #339933;">=</span> JAXBContext.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>Employee.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">StringWriter</span> writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        jaxbContext.<span style="color: #006633;">createMarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">marshal</span><span style="color: #009900;">&#40;</span>john, writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// read it from XML</span>
        <span style="color: #000000; font-weight: bold;">final</span> Employee johnRead <span style="color: #339933;">=</span>
            <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> jaxbContext.<span style="color: #006633;">createUnmarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">unmarshal</span><span style="color: #009900;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringReader</span><span style="color: #009900;">&#40;</span>writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>john.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>johnRead<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// write the new object out as XML again.</span>
            writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            jaxbContext.<span style="color: #006633;">createMarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">marshal</span><span style="color: #009900;">&#40;</span>johnRead, writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">&quot;johnRead was identical to john: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;john and johnRead are not equal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @XmlAttribute
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's first name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> firstName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's middle name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> middleName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's last name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> lastName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastName</span> <span style="color: #339933;">=</span> lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMiddleName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> middleName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMiddleName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> middleName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">middleName</span> <span style="color: #339933;">=</span> middleName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFirstName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> firstName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">firstName</span> <span style="color: #339933;">=</span> firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> o<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        Employee employee <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> o<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">!=</span> employee.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>firstName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>firstName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">firstName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">firstName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>lastName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">lastName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">lastName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>middleName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>middleName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">middleName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">middleName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> hashCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>firstName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> firstName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>middleName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> middleName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>lastName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> lastName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Employee{&quot;</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;id=&quot;</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, firstName='&quot;</span> <span style="color: #339933;">+</span> firstName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, middleName='&quot;</span> <span style="color: #339933;">+</span> middleName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, lastName='&quot;</span> <span style="color: #339933;">+</span> lastName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">'}'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The following commands will compile and run the source, if under a unix OS.  If in windows, you'll need to form your own classpath.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">javac <span style="color: #660033;">-classpath</span> .:$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> jar <span style="color: #000000; font-weight: bold;">in</span> libs<span style="color: #000000; font-weight: bold;">/*</span>.jar; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$jar</span>:&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Employee.java
java <span style="color: #660033;">-classpath</span> .:$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> jar <span style="color: #000000; font-weight: bold;">in</span> libs<span style="color: #000000; font-weight: bold;">/*</span>.jar; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$jar</span>:&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Employee</pre></div></div>

<p>The output should be as follows, but the XML will be on a single line...</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">johnRead was identical to john<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span> standalone<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;yes&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>employee id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>firstName<span style="color: #339933;">&gt;</span>John<span style="color: #339933;">&lt;/</span>firstName<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>middleName<span style="color: #339933;">&gt;</span>Robert<span style="color: #339933;">&lt;/</span>middleName<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>lastName<span style="color: #339933;">&gt;</span>Doe<span style="color: #339933;">&lt;/</span>lastName<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>employee<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>ZK AJAX Status Bar</title>
		<link>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/</link>
		<comments>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 08:45:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=172</guid>
		<description><![CDATA[Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.

Features
I [...]]]></description>
			<content:encoded><![CDATA[<p>Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.</p>
<p><span id="more-172"></span></p>
<h2>Features</h2>
<p>I thought it important to have some useful features that make sense for what I've seen in status bars.</p>
<ul>
<li>a method to set the status, with a delay before the status bar is cleared</li>
<li>a method to simply set the status, and leave it as is.  It would be up to the developer to clear the status later, if need be.  Or, the next status item would take over.</li>
<li>a very simple interface abstraction in case we want to change the type of component we use later, or something of that nature.  This will help us prevent the need to refactor a lot of code that could be using the status bar; we would only need to refactor the implementing class of the interface, leaving all of the code accessing the status bar entirely intact.</li>
</ul>
<p>Future features might include...</p>
<ul>
<li>methods for setting the status with color text</li>
<li>methods for setting the status with html</li>
<li>any other suggestions are welcome.</li>
</ul>
<h2>Window Width Status Bar</h2>
<p>We first, of course, need to setup the actual status bar.  So, right before the end of the window, we do just that, with a "textbox".  Now, there's no reason you can't use some other type of control, if it makes sense to.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textbox</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;1.2em&quot;</span> <span style="color: #000066;">sclass</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">readonly</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;com.example.system.StatusBar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;timer</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;statusTimer&quot;</span> <span style="color: #000066;">running</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">repeats</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">onTimer</span>=<span style="color: #ff0000;">'status.setText(&quot;&quot;);'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>The text box is implemented by a custom class, which we'll delve into in a moment.  We also have a ZK timer, for implementing the automatic clearing feature, because it is illegal to access ZK elements from outside of a ZK event.  i.e. You cannot write your own thread to do it at a later time, as ZK will throw an <strong><span style="color: #3366ff;">IllegalStateException</span></strong>.</p>
<h2>The Code</h2>
<h3>Interface Abstraction</h3>
<p>We've kept the interface very simple, just two methods.  For more information, read the javadoc comments.</p>
<ul>
<li>setStatus(String) allows setting of the status bar permanently</li>
<li>setStatus(String, int) allows setting of the status bar, and automatic clearing of it after a specified delay</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Handles setting of status bar messages.  All calls to this object must be
 * done from within the ZK framework, such as inside an event.
 *
 * Hides the details of what component is actually a status bar.  It could be a
 * textbox, or something else, but we don't want to be dependant on any specific
 * type of control, in case it changes in the future.
 *
 * Created :  Jan 31, 2010 1:39:37 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IStatusBar
<span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text for the time period indicated.
     *
     * @param statusText status text
     * @param timePeriod delay in seconds, before the status bar will be
     *                   cleared.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text.  Pass null to clear.
     *
     * @param statusText status text or null to clear
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the status text of the status bar.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Implementation</h3>
<p>Essentially, all we are doing with the implement is as follows</p>
<ul>
<li>implement AfterCompose, so we can setup a session variable to access the status bar from any ZK code, without much trouble</li>
<li>implement the setStatus() methods as described in the feature section.  One takes an extra argument for a delay, indicating how long before the status bar should be cleared.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.ext.AfterCompose</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Textbox</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Timer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * StatusBar handles setting the status bar text, and clearing it after a given
 * timeout.  Implements IStatusBar, to hide the details of what a status bar is
 * from the client code.  We use a textbox, but we could change that, who knows.
 *
 * Created :  Jan 31, 2010 12:42:29 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StatusBar <span style="color: #000000; font-weight: bold;">extends</span> Textbox <span style="color: #000000; font-weight: bold;">implements</span> AfterCompose, IStatusBar
<span style="color: #009900;">&#123;</span>
    @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;ConstantNamingConvention&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>StatusBar.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> StatusBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterCompose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status bar running as &quot;</span> <span style="color: #339933;">+</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// TODO find a better method, getFellow() didn't work</span>
        <span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setStatus<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// the timer must be in the page, or the page is inactive and this</span>
        <span style="color: #666666; font-style: italic;">// call would never happen?</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Timer</span> timer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Timer</span><span style="color: #009900;">&#41;</span> getFellow<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;statusTimer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">setDelay</span><span style="color: #009900;">&#40;</span>timePeriod <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setText<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Using the Status Bar</h3>
<p>The following code must be used inside of a ZK event handler, such as one that comes from the click of a button, or a mouse over event, etc.  Basically, all we're doing is grabbing the status bar object from the session, and request the status be set.  That's all there is to it.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> IStatusBar statusBar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IStatusBar<span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
statusBar.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Transaction Posted&quot;</span>, <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Results</h2>
<p>I'm attaching a screen shot of the results of my status bar.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png"><img class="alignnone size-full wp-image-177" title="status-bar" src="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png" alt="ZK Status bar" width="530" height="148" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZK Exception Handling and Error Popup</title>
		<link>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/</link>
		<comments>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 01:28:09 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=160</guid>
		<description><![CDATA[Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I [...]]]></description>
			<content:encoded><![CDATA[<p>Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I wanted to do, and I didn't have to write an once of code.  All I did was write some ZUL, which wrapped a JSP inside of a ZK window.  I share how I did that in this post.</p>
<p><span id="more-160"></span></p>
<h2>Configuration</h2>
<p>The first thing to do is to configure ZK to handle your unhandled exceptions, and target a ZUL page for rendering.  This is done through the zk.xml file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>java.lang.Throwable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/error.zul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>ZK error.zul</h2>
<p>The second thing to do is create an error.zul page, which I pulled mostly from the ZK Developers Guide.  I added the bit where I include my error.jsp file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zk</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;window</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;modal&quot;</span> <span style="color: #000066;">sizable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Error ${requesScope['javax.servlet.error.status_code']}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/jsp/error.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;margin-left:auto; margin-right:auto; text-align: center;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Okay&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;spaceOwner.detach()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Reload Page&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;Executions.sendRedirect(null)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/zk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>JSP error.jsp</h2>
<p>I basically pulled this error page from the standard error page that I normally use, and tailored it a bit.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.PrintWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.StringWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;com.example.util.Util&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">isErrorPage</span>=<span style="color: #ff0000;">&quot;true&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;ce&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/functions&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;fn&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://jakarta.apache.org/taglibs/string-1.1&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;st&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- BEGIN error.jsp --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An error has occured. If you believe this error is a system problem, and you
  continue to get this error, please contact a special person via
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;mailto:'me@example.com' &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>email<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;&lt;%=Util.getBooleanItem(\&quot;</span>/debug\<span style="color: #ff0000;">&quot;)%&gt;</span></span>&quot;&gt;
    <span style="color: #009900;">&lt;%</span>
<span style="color: #009900;">      StringWriter sw = new StringWriter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      PrintWriter pw = new PrintWriter<span style="color: #66cc66;">&#40;</span>sw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      exception.printStackTrace<span style="color: #66cc66;">&#40;</span>pw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">    %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:set</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;exceptionStack&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=sw.toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;debug&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Message : <span style="color: #009900;">&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Exception : <span style="color: #009900;">&lt;%=exception.getClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Stack : ${fn:escapeXml(exceptionStack)}
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- END error.jsp --&gt;</span></pre></div></div>

<h2>Sample Error Page</h2>
<p>And, we have the result;  it looks quite nice.  If debug were enabled, it would have my stack trace displayed in a wrap-able fixed width font ; providing much easier diagnostics during development.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png"><img class="alignnone size-full wp-image-186" title="ZK Sample Error" src="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png" alt="ZK Sample Error Page" width="558" height="196" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

