<?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>Megatome &#187; java</title>
	<atom:link href="http://www.megatome.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.megatome.com</link>
	<description>Just another idiot&#039;s ramblings</description>
	<lastBuildDate>Thu, 12 Jan 2012 00:45:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Open PDF in New Window with Seam</title>
		<link>http://www.megatome.com/2009/10/12/open-pdf-in-new-window-with-seam/</link>
		<comments>http://www.megatome.com/2009/10/12/open-pdf-in-new-window-with-seam/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 18:35:15 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Making]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[seam]]></category>

		<guid isPermaLink="false">http://www.megatome.com/?p=76</guid>
		<description><![CDATA[A simple method to open PDFs in a new window while displaying validation errors in the original window. The PDF window will not open if there are validation or other messages.]]></description>
			<content:encoded><![CDATA[<p>For a recent Seam development project, I had the task of creating a PDF report from some user input and displaying the result in a new window.</p>
<p>Initially, I used a <code>&lt;h:commandLink/&gt;</code> with <code>target="_blank"</code>. This worked well until the user entered criteria that failed validation. The new window was still created, and the validation messages were shown in the new window. This was not a good solution, so after some research and experimentation I came up a solution that meets the following criteria:
</p>
<ul>
<li>Validation messages are shown in original window.</li>
<li>A new window is not created when there are validation messages.</li>
<li>A new window is not created when the entered criteria returns zero (0) results.</li>
</ul>
<h3>The Action Class</h3>
<p>For this example, the action class is very simple:</p>
<pre name="code" class="brush: java">
public String getReportURL() {
    return "/pdfpopup/reports/reportDisplay.seam";
}

// Getters and setters omitted

public List&lt;String&gt; getReportData() {
    return reportData;
}

public void doSearch() {
    // This is where the work would actually happen
    reportData = new ArrayList&lt;String&gt;();
    for (int i = 0; i < selectOneValue; i++) {
         reportData.add("Report Row " + (i + 1));
    }
    if (reportData.isEmpty()) {
        facesMessages.add("Report will be empty, not popping up");
    }
}
</pre>
<p>I added the <code>getReportURL()</code> method to the action because there may be occasions where the report URL differs based on criteria. In the application I worked on, we had to support PDF and Excel reports, so the method returned the correct URL.</p>
<p>The action simply takes the criteria specified on the JSF page and populates a list of results based on that criteria. The PDF generation page will access the list later.</p>
<h3>The JSF Page</h3>
<p>The JSF page looks like this:
</pre>
<pre class="brush:xml">
&lt;ui:define name="body">
  &lt;script type="text/javascript">
  //&lt;![CDATA[
  function showReport(conversationId) {
  if (document.getElementById("messages") != null) {
    return;
  }
  var reportWin = window.open('#{reportAction.reportURL}' + '?cid=' + conversationId);
  if (!reportWin) {
    alert("Could not open the report window. Please disable popup blocking for this website and try again.");
  }
  }
  // ]]&gt;
  &lt;/script>
  &lt;h:form id="generateReport">
  &lt;s:validateAll>
  &lt;h:panelGrid width="100%" columns="1" style="text-align: center; font-weight:bold; font-size: 12px">
    &lt;h:outputText value="Report Query"/>
  &lt;/h:panelGrid>
  &lt;h:panelGrid columns="2" border="0" frame="none" style="padding-top:30px;">
    &lt;h:outputLabel for="selectOneValue">Number of Output Rows&lt;/h:outputLabel>
    &lt;h:selectOneMenu id="selectOneValue" value="#{reportAction.selectOneValue}" required="true">
      &lt;f:selectItem itemLabel="Zero" itemValue="0"/>
      &lt;f:selectItem itemLabel="One" itemValue="1"/>
      &lt;f:selectItem itemLabel="Two" itemValue="2"/>
      &lt;f:selectItem itemLabel="Three" itemValue="3"/>
      &lt;f:selectItem itemLabel="Four" itemValue="4"/>
    &lt;/h:selectOneMenu>
    &lt;h:outputLabel for="startDate">Report Period:&lt;/h:outputLabel>
    &lt;h:panelGroup>
      &lt;rich:calendar id="startDate" enableManualInput="true"
        value="#{reportAction.startDate}" showWeeksBar="false" datePattern="MM/dd/yyyy"
        immediate="true" required="true" label="Report Start Date"/>
      &lt;h:outputLabel for="endDate">through&lt;/h:outputLabel>
      &lt;rich:calendar id="endDate" enableManualInput="true"
        value="#{reportAction.endDate}" showWeeksBar="false" datePattern="MM/dd/yyyy"
        immediate="true" required="true" label="Report End Date"/>
    &lt;/h:panelGroup>
    &lt;a4j:commandButton id="getReportLink" action="#{reportAction.doSearch}"
         value="Get Report" oncomplete="showReport('#{conversation.id}')"/>
  &lt;/h:panelGrid>
  &lt;/s:validateAll>
  &lt;/h:form>
&lt;/ui:define>
</pre>
<p>This is really the guts of the operation. When the <code>commandButton</code> is clicked, the <code>doSearch()</code> method will be executed. Once that call is complete, the <code>oncomplete</code> handler will be called. </p>
<p>The page template is configured so that any <code>FacesMessages</code> will be displayed in an element with id &#8220;<code>messages</code>&#8220;. If this element is present, we assume that either a validation error or no data message is being displayed and do not show the PDF. If the element is not present, everything is OK and we open the new window with the URL for the PDF. Note that it&#8217;s crucial to pass the conversation ID along so that the data loaded by the action will be visible to the page creating the PDF.
</p>
<h3>The PDF</h3>
<p>For completeness, here&#8217;s the sample page I&#8217;m using to create a PDF:</p>
<pre class="brush:xml">
&lt;p:document xmlns:p="http://jboss.com/products/seam/pdf"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:f="http://java.sun.com/jsf/core"
   title="Sample PDF Report">
&lt;f:facet name="header">
  &lt;p:font size="12">
    &lt;p:header borderWidthTop="0" borderWidthBottom="0.4" alignment="center">
      &lt;p:paragraph indentationLeft="50">REPORT HEADER&lt;/p:paragraph>
    &lt;/p:header>
    &lt;p:footer borderWidthTop="1" borderColorTop="black" borderWidthBottom="0" alignment="center">
      [&lt;p:pageNumber/>]
    &lt;/p:footer>
  &lt;/p:font>
&lt;/f:facet>
&lt;ui:repeat var="item" value="#{reportAction.reportData}">
  &lt;p:font size="8">
    &lt;p:table columns="1" headerRows="1" widthPercentage="100">
      &lt;p:font style="bold">
        &lt;p:cell verticalAlignment="bottom">Report Data&lt;/p:cell>
      &lt;/p:font>
      &lt;p:cell>#{item}&lt;/p:cell>
    &lt;/p:table>
  &lt;/p:font>
&lt;/ui:repeat>
&lt;/p:document>
</pre>
<h3>Full Sample Code</h3>
<p>You can view and download the full sample code for this solution from <a href="https://github.com/iamthechad/pdfpopup">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2009/10/12/open-pdf-in-new-window-with-seam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Phone Screen Works Both Ways</title>
		<link>http://www.megatome.com/2009/09/08/the-phone-screen-works-both-ways/</link>
		<comments>http://www.megatome.com/2009/09/08/the-phone-screen-works-both-ways/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 21:06:08 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Living]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jobs]]></category>

		<guid isPermaLink="false">http://www.megatome.com/?p=74</guid>
		<description><![CDATA[A phone screen is typically used to screen applicants for a job, but it gave me enough information to make a decision about not wanting to work for the company.]]></description>
			<content:encoded><![CDATA[<p>I recently applied for a position through a recruiting service. I jumped through the requisite hoops and was told that the prospective employer was very excited to talk to me.</p>
<p>The standard procedure for this employer is to give candidates a simple phone screen before arranging an interview. Personally, I feel that having one person make a decision about whether or not I&#8217;ll &#8220;fit well with the team&#8221; after 10 minutes on the phone is ludicrous, but that&#8217;s the game I had to play.</p>
<p><a href="http://www.flickr.com/photos/nichollsphotos/2906834393/"><img src="http://farm4.static.flickr.com/3254/2906834393_e4ef4ae70e_m.jpg" alt="Tin Can Phone" style="float:right; margin: 5px"/></a></p>
<p>During the phone call, I was asked several generic questions about Java. I gave what I felt was correct answers to the questions, but the interviewer wasn&#8217;t happy with my results. Every time I answered a question, I heard &#8220;Well, I was looking for&#8230;&#8221;, with the expected answer simply being a different wording of what I had said.</p>
<p>I chalked this up to the interviewer simply being used to different terminology than I for the same concepts, so I was a bit surprised when I wasn&#8217;t called in for an in-person interview. It wasn&#8217;t until a few days later that I realized that the answers I was expected to give told me quite a bit about the company, and that I wouldn&#8217;t have been happy working there had I been offered the job.</p>
<p>The particular question that stuck in my mind was a simple one. &#8220;What are some of the benefits of the introduction of generics in Java, especially in collections?&#8221;</p>
<p>I gave the answer that pretty much anybody familiar with Java generics would give: compile-time type checking, no need for casting objects, etc. What I got from the interviewer was &#8220;Well, I was looking for the fact that you don&#8217;t have to do <code>instanceof</code> checks all over any more.&#8221;</p>
<p>On the surface, this may seem like another way of saying what I said, but it&#8217;s actually quite different.</p>
<p>Before generics, you would need to cast objects to the proper class when retrieving them from a collection. This does not mean that you would be using <code>instanceof</code> to do this. The only situation I can think of that requires using <code>instanceof</code> with a collection is if there are a lot of heterogenous objects in the collection.</p>
<p>There are limited situations where storing different object types in the same collection makes sense. Most of the time, however, this is a sign of either lazy development or not understanding the collection mechanism very well.</p>
<p>
<a href="http://www.flickr.com/photos/davesag/8519770/"><br />
<img src="http://farm1.static.flickr.com/8/8519770_e9043bc645_m.jpg" alt="More Bad Code" style="float:left;margin:5px"/></a></p>
<p>It&#8217;s generally a good idea to only put one type of object into a collection. This makes it much easier to work with and avoids any need for <code>instanceof</code> checks. By &#8220;one type of object&#8221;, I don&#8217;t mean that all of the objects need to be the exact same class. Chances are good that all of the objects being placed into a collection have some relationship; perhaps they will all implement the same interface.</p>
<p>I may have completely misinterpreted the interviewer, but I have a very strong impression that he and perhaps others on his team are used to using collections as grab bags of widely different things. Personally, I wouldn&#8217;t want to maintain that code. I can hope that the addition of generics to Java has forced the interviewer to change at least one practice for the better. I&#8217;m glad I wasn&#8217;t called in for the job &#8211; who knows how many more &#8220;well, at least it works&#8221; practices are being followed? I&#8217;ve got enough of those at my current job; I don&#8217;t need to learn a new set.</p>
<p>Images:</p>
<p>Tin Can:
<div xmlns:cc="http://creativecommons.org/ns#" about="http://www.flickr.com/photos/nichollsphotos/2906834393/"><a rel="cc:attributionURL" href="http://www.flickr.com/photos/nichollsphotos/">http://www.flickr.com/photos/nichollsphotos/</a> / <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/">CC BY-NC-ND 2.0</a></div>
<p>Java Code:</p>
<div xmlns:cc="http://creativecommons.org/ns#" about="http://www.flickr.com/photos/davesag/8519770/"><a rel="cc:attributionURL" href="http://www.flickr.com/photos/davesag/">http://www.flickr.com/photos/davesag/</a> / <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.0/">CC BY-NC-SA 2.0</a></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2009/09/08/the-phone-screen-works-both-ways/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frame2 and MacOS X</title>
		<link>http://www.megatome.com/2008/01/14/frame2-and-macos-x/</link>
		<comments>http://www.megatome.com/2008/01/14/frame2-and-macos-x/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 04:05:56 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[frame2]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[java6]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[web-application-framework]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/23</guid>
		<description><![CDATA[Currently, Frame2 does not work on Macs. This, of course, is due to the fact that there is no (easily) available Java 6 implementation for MacOS. I&#8217;ve been trying to decide if this is an issue or not. Reasons why it might be an issue: I use a Mac for most of development, and I [...]]]></description>
			<content:encoded><![CDATA[<p>Currently, Frame2 does not work on Macs. This, of course, is due to the fact that there is no (easily) available Java 6 implementation for MacOS. I&#8217;ve been trying to decide if this is an issue or not.</p>
<p>Reasons why it might be an issue:</p>
<ul>
<li>I use a Mac for most of development, and I hate having to drop into an emulator to work on Frame2</li>
<li>I really would like Frame2 to run on the Mac, if just for completeness.</li>
</ul>
<p>Reasons why it probably doesn&#8217;t matter:</p>
<ul>
<li>Who really runs Java webapps on Macs? Tomcat on Windows or Linux is OK, but it just feels dirty to me on the Mac.</li>
</ul>
<p>Hopefully, there will be a version of Java 6 available for the Mac soon. At that point, I&#8217;ll probably make the necessary updates to make everything work. Until then, if you&#8217;re writing a web app and using a Mac &#8211; go with Rails.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2008/01/14/frame2-and-macos-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build Web Services with the Plugin</title>
		<link>http://www.megatome.com/2007/09/17/build-web-services-with-the-plugin/</link>
		<comments>http://www.megatome.com/2007/09/17/build-web-services-with-the-plugin/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 19:23:27 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[frame2]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[sourceforge]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[web-application-framework]]></category>
		<category><![CDATA[web-services]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/18</guid>
		<description><![CDATA[The Eclipse plugin has just been updated, and a new plugin has been added to the mix. The new plugin allows users to create Frame2 projects with web services support by adding all of the required libraries and initial configuration. Also in the new plugin are two wizards: one for creating new Responders and one [...]]]></description>
			<content:encoded><![CDATA[<p>The Eclipse plugin has just been updated, and a new plugin has been added to the mix. The new plugin allows users to create Frame2 projects with web services support by adding all of the required libraries and initial configuration. Also in the new plugin are two wizards: one for creating new Responders and one for creating Schema mappings. The Getting Started guide has also been expanded to explain how to add web services support to the example application.</p>
<p>Again, the Update Manager site is the preferred method for downloading the plugins, since it will gracefully handle version and dependency conflicts.</p>
<p>Update Site for Eclipse:<br />
<a href="http://frame2.megatome.com/eclipse">http://frame2.megatome.com/eclipse</a></p>
<p>Sourceforge Downloads:<br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=102634&amp;package_id=112600&amp;release_id=540150">Main Eclipse Plugin</a><br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=102634&amp;package_id=245903&amp;release_id=540154">Web Services Eclipse Plugin</a> (requires at least version 1.3.3 of the regular plugin)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/09/17/build-web-services-with-the-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Plugin Nearly Ready</title>
		<link>http://www.megatome.com/2007/09/10/eclipse-plugin-nearly-ready/</link>
		<comments>http://www.megatome.com/2007/09/10/eclipse-plugin-nearly-ready/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 22:25:31 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[frame2]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sourceforge]]></category>
		<category><![CDATA[web-application-framework]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/16</guid>
		<description><![CDATA[As the title says, the Eclipse plugin for Frame2 is almost done. Of course, &#8220;done&#8221; is a relative term. In this case, it means that the plugin has been updated to work with the latest version of the framework, including the updated DTD. Unfortunately, it also means that it still has the same limitations that [...]]]></description>
			<content:encoded><![CDATA[<p>As the title says, the Eclipse plugin for Frame2 is almost done. Of course, &#8220;done&#8221; is a relative term. In this case, it means that the plugin has been updated to work with the latest version of the framework, including the updated DTD. Unfortunately, it also means that it still has the same limitations that previous versions have had. Specifically, the plugin still does not support creating a Frame2 project with web services support. This can be added by hand and the Frame2 plugin won&#8217;t stomp on it, but neither are there any nice wizards for the web services tasks. This limitation is the next item on my list &#8211; I&#8217;m pretty sure that I can create an optional plugin that can be downloaded that will add the web services functionality for anyone that wants it. This will also help keep the download size of the &#8220;core&#8221; plugin as small as possible.</p>
<p>One other feature that the plugin is missing is a contextual editor for the Frame2 configuration file. It would nice to be able to get contextual help and hints when editing the config by hand, but I don&#8217;t think I have the time in the forseeable future to research how this works in Eclipse.</p>
<p>The plugin will be available for download from Sourceforge and I will be creating an update site here at frame2.megatome.com that will be the preferred way of getting the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/09/10/eclipse-plugin-nearly-ready/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Version 1.3 is Released</title>
		<link>http://www.megatome.com/2007/09/07/version-13-is-released/</link>
		<comments>http://www.megatome.com/2007/09/07/version-13-is-released/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 14:57:44 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[frame2]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[sourceforge]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[web-application-framework]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/15</guid>
		<description><![CDATA[Version 1.3 of Frame2 is officially available. The framework can be downloaded here, and the sample applications are available here. Work on the Eclipse plugin continues, with a (hopeful) release date in the next week or two.]]></description>
			<content:encoded><![CDATA[<p>Version 1.3 of Frame2 is officially available. The framework can be downloaded <a href="http://sourceforge.net/project/showfiles.php?group_id=102634&amp;package_id=110038&amp;release_id=537771">here</a>, and the sample applications are available <a href="http://sourceforge.net/project/showfiles.php?group_id=102634&amp;package_id=130798&amp;release_id=537853">here</a>.</p>
<p>Work on the Eclipse plugin continues, with a (hopeful) release date in the next week or two.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/09/07/version-13-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Features Uncovers Old Bugs</title>
		<link>http://www.megatome.com/2007/09/04/adding-features-uncovers-old-bugs/</link>
		<comments>http://www.megatome.com/2007/09/04/adding-features-uncovers-old-bugs/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 22:46:19 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[frame2]]></category>
		<category><![CDATA[java6]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[test-driven-development]]></category>
		<category><![CDATA[web-application-framework]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/10</guid>
		<description><![CDATA[This seems to happen to me no matter what project I&#8217;m on. I try to implement a simple (or not so simple) feature and end up exposing at least one bug that&#8217;s been hiding around for quite some time. As an illustration, I was adding a feature to Frame2 today to allow some parameters to [...]]]></description>
			<content:encoded><![CDATA[<p>This seems to happen to me no matter what project I&#8217;m on. I try to implement a simple (or not so simple) feature and end up exposing at least one bug that&#8217;s been hiding around for quite some time.</p>
<p>As an illustration, I was adding a feature to Frame2 today to allow some parameters to be passed between events within a mapping &#8211; without making developers use the <code>HttpSession</code>. After a couple of false starts, I had a pretty good idea of how to make the changes and starting ripping out code. I came up with several unit tests, and modifying code to make the tests pass. Pretty standard <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a>&#8230;until I wrote the test that made sure event chain validation was working.</p>
<p>Before I explain the bug, I&#8217;ll give a high level description of how Frame2 works when submitting form data:</p>
<ol>
<li>Form is filled out by user and submitted.</li>
<li>Frame2 looks up the appropriate event from the form action.</li>
<li>An instance of the appropriate event is created and populated by the introspector.</li>
<li>Based on the mapping for the event, Frame2 will then validate the event. This may involve the <a href="http://commons.apache.org/validator/">Commons Validator</a> if it is enabled and/or overriding the <code>Event.validate()</code> method.</li>
<li>If validation fails, the mapping must specify a location for the framework to forward back to. This is usually the same page where the data was entered.</li>
<li>If validation passes, the framework then iterates through the list of event handlers, calling the <code>handle()</code> method. If <code>handle()</code> returns null, the framework continues to the next handler. A non-null result usually indicates an error, and the framework will forward to the location named by the result.</li>
<li>Once all of the handlers have been invoked, the framework will default to the view specified in the mapping. Usually this is just a JSP, but Frame2 supports forwarding to events &#8211; called &#8220;chaining&#8221;.</li>
<li>For the chained event, Frame2 is supposed to start back at step 2 and continue processing until it gets to the end of the chain.</li>
</ol>
<p>Notice how I say &#8220;supposed to&#8221; in step 9? The framework was actually only going back to step 6, bypassing validation for all events except the first in the chain. Subtle, yes, and unlikely to be noticed by most users &#8211; but it&#8217;s still a bug. The bug has now been fixed so that the framework goes back to step 2 like it&#8217;s supposed to.</p>
<p>In case you&#8217;re wondering what use event chaining is, here&#8217;s an example:</p>
<ol>
<li>User enters a blog entry and submits the form.</li>
<li>Frame2 validates the form data and begins invoking handlers.</li>
<li>The blog entry handler persists the data, perhaps to a database.</li>
<li>The default view for the event mapping tells the framework to forward to the &#8220;View All Blog Entries&#8221; event.</li>
<li>The framework creates the appropriate object and begins invoking the handlers in the &#8220;View All&#8221; mapping.</li>
<li>The &#8220;View All&#8221; handler populates all of the blog entries into the &#8220;View All&#8221; event.</li>
<li>The default view for the &#8220;View All&#8221; mapping is a JSP page, which renders the blog entries using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</li>
</ol>
<p>Chaining allows the &#8220;View All&#8221; event to remain its own entity that can be  invoked separately, while allowing the same functionality to be used in other places where appropriate.</p>
<p>By way of comparison, the feature I added allows the above sequence to be reworked like this:</p>
<ol>
<li>User enters a blog entry and submits the form.</li>
<li>Frame2 validates the form data and begins invoking handlers.</li>
<li>The blog entry handler persists the data, perhaps to a database.</li>
<li>The blog entry handler sets an attribute with the new entry id into the context.</li>
<li>The default view for the event mapping tells the framework to forward to the &#8220;View Specific Blog Entry&#8221; event.</li>
<li>The framework creates the appropriate object and uses the context value(s) with the introspector to set some values in the event.</li>
<li>The framework then begins invoking the handlers in the &#8220;View Specific&#8221; mapping.</li>
<li>The &#8220;View Specific&#8221; handler looks up the entry with the specified id and sets its data into the event.</li>
<li>The default view for the &#8220;View Specific&#8221; mapping is a JSP page, which renders the blog entry using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/09/04/adding-features-uncovers-old-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Approaching the Finish Line</title>
		<link>http://www.megatome.com/2007/08/31/approaching-the-finish-line/</link>
		<comments>http://www.megatome.com/2007/08/31/approaching-the-finish-line/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 20:34:33 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[frame2]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[sourceforge]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[web-application-framework]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/9</guid>
		<description><![CDATA[Frame2 is almost ready to be released as a new version. I may still make some changes, but it&#8217;s definitely in Release Candidate stage now. There are only a few things that I may add before testing the heck out of it: Upgrade unit tests to JUnit 4. There are a lot of tests, especially [...]]]></description>
			<content:encoded><![CDATA[<p>Frame2 is almost ready to be released as a new version. I may still make some changes, but it&#8217;s definitely in Release Candidate stage now. There are only a few things that I may add before testing the heck out of it:</p>
<ul>
<li>Upgrade unit tests to <a href="http://www.junit.org/index.htm">JUnit 4</a>. There are a lot of tests, especially the ones that mock a servlet container, that do a lot of repetitive work in <code>setUp()</code> . JUnit 4 has finally brought the ability to annotate methods to be run before and after all tests in the class with <code>@BeforeClass</code> and <code>@AfterClass</code>, respectively. Individual test setup activities can still be performed by annotating a method with <code>@Before</code>.</li>
<li>Fix outstanding bugs. There&#8217;s only one right now, and it&#8217;s SOAP specific, so I may or may not fix it. It may take me longer to figure out how to reproduce the problem with unit tests than it&#8217;s worth.</li>
<li>Add outstanding feature requests. Again, there&#8217;s only one, but it&#8217;s (in my opinion) a biggie &#8211; the ability to add parameters to the response when handling an event.</li>
<li>Doc updates. The web services doc needs to be written, and I&#8217;m sure all of the other doc needs a good examination.</li>
</ul>
<p>I&#8217;ll be testing the latest build with a web application that I&#8217;ve been working on for years that I&#8217;ve come to think of as an unofficial reference implementation of Frame2. I haven&#8217;t decided yet if the web app should become part of the project on Sourceforge or not. We&#8217;ll see.</p>
<p>Once the testing is done and I&#8217;ve released a new version of Frame2, I plan on working on the <a href="http://sourceforge.net/project/showfiles.php?group_id=102634&amp;package_id=112600">Eclipse plugin</a>. The poor plugin has pretty much been ignored for several years now, and it needs some attention.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/08/31/approaching-the-finish-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Consistent API is a Very Good Thing</title>
		<link>http://www.megatome.com/2007/08/30/a-consistent-api-is-a-very-good-thing/</link>
		<comments>http://www.megatome.com/2007/08/30/a-consistent-api-is-a-very-good-thing/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 20:24:56 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[frame2]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/8</guid>
		<description><![CDATA[I&#8217;ve been mucking around in the codebase, cleaning up pieces of the API that annoy me. Some bright person thought that it was a good idea to have a method that returns an Iterator to access a collection. I&#8217;ve been cleaning up all of these methods, changing them so that they return an actual collection [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been mucking around in the codebase, cleaning up pieces of the API that annoy me. Some bright person thought that it was a good idea to have a method that returns an <code>Iterator</code> to access a collection. I&#8217;ve been cleaning up all of these methods, changing them so that they return an actual collection &#8211; occasionally made unmodifiable through the <code>Collections</code> class.</p>
<p>Naturally, this has led to unit test failures. Almost all of the failures have been easy to fix, but once in a while one pops up that makes me scratch my head. Here&#8217;s an example:</p>
<pre name="code" class="brush: java">
public void testGetIfEmpty() {
    assertTrue(this.errors.isEmpty());
    assertNull(this.errors.get(FOO));
    assertEquals(0, this.errors.get().length);
    assertEquals(0, this.errors.get(FOO).length);
}</pre>
<p>In this instance, <code>errors</code> is a class that aggregates individual <code>Error</code> objects. The <code>get(String)</code> method returns an array of <code>Error</code> objects that have the specified key, while <code>get()</code> retrieves all <code>Error</code>s. Pretty simple, right? After my changes, the test fails on the <code>assertNull()</code> statement, which isn&#8217;t surprising.</p>
<p>The failing statement read <code>assertNull(this.errors.iterator(FOO))</code> before I removed the <code>iterator()</code> method, which tells us a bit about how the API was originally coded. The <code>iterator(String)</code> returned <code>null</code> if there were no matching entries. However, as the unit test clearly shows, <code>get(String)</code> returns an empty array when it doesn&#8217;t find any matching <code>Error</code>s. Quite the difference, and potentially confusing &#8211; the developer has to remember which method may return <code>null</code>.</p>
<p>The API has now been changed to return an empty collection instead of <code>null</code> when no matching errors are found. Now, a user of the API simply has to call the method and loop over the result (zero times if it&#8217;s empty) without having to make <code>null</code> checks.</p>
<p>Whoever wrote this unit test obviously knew that one method returned <code>null</code> while the other returned an empty array for the same input, since the test passed. I only wish that person would have looked at those lines and noticed the inconsistency, instead of leaving it for me to find.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/08/30/a-consistent-api-is-a-very-good-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FindBugs Is Even Cooler Than I Thought</title>
		<link>http://www.megatome.com/2007/08/29/findbugs-is-even-cooler-than-i-thought/</link>
		<comments>http://www.megatome.com/2007/08/29/findbugs-is-even-cooler-than-i-thought/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 22:21:08 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[findbugs]]></category>
		<category><![CDATA[frame2]]></category>
		<category><![CDATA[java6]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oss]]></category>

		<guid isPermaLink="false">http://frame2.megatome.com/archives/7</guid>
		<description><![CDATA[I&#8217;ve mentioned before that I&#8217;m using FindBugs to help make sure that the Frame2 code is up to snuff. The Eclipse compiler can catch a lot of things, bug FindBugs has some neat tricks up its sleeve to find things that Eclipse can&#8217;t. FindBugs uses static analysis of the code to search for patterns that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve mentioned before that I&#8217;m using <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> to help make sure that the Frame2 code is up to snuff. The Eclipse compiler can catch a lot of things, bug <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> has some neat tricks up its sleeve to find things that Eclipse can&#8217;t. <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> uses static analysis of the code to search for patterns that indicate possible issues. Being the Type A person that I am, I always turn on all of the possible matches and whittle the list down. Quite often, however, <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> will find a false positive or two. Up until now, I&#8217;ve either tried to rework the code to avoid the warning or disabled the category altogether. I&#8217;ve never liked the approach of turning off a whole category just to avoid seeing a warning or two, so I spent the morning muttering to myself how useful it would be if <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> allowed me to ignore certain warnings like I can do with <code>@SuppressWarnings</code>.</p>
<p>Then I went and <a href="http://findbugs.sourceforge.net/manual/index.html">RTFM</a>.</p>
<p><a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> has a <a href="http://findbugs.sourceforge.net/manual/filter.html">filtering system</a> that makes <code>@SuppressWarnings</code> look amateur. Here&#8217;s an example: in the <code>SoapRequestProcessor</code>, <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> marked a warning that an <code>Exception</code> was being caught when no <code>Exception</code> was being thrown. After looking at the code and verifying that the try block in question throws several different exceptions, I created a filter entry. The entry looks like this:</p>
<p><code>&lt;Match&gt;<br />
&lt;Class name="org.megatome.frame2.front.SoapRequestProcessor"/&gt;<br />
&lt;Method name="getEvents"/&gt;<br />
&lt;Bug pattern="REC_CATCH_EXCEPTION"/&gt;<br />
&lt;/Match&gt;</code></p>
<p>This tells <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a> to match a specific bug type in a specified method in a desired class. This entry can be used in both an inclusion or exclusion filter &#8211; I use it to exclude that warning from the results.</p>
<p>Here&#8217;s a more complex example:</p>
<p><code>&lt;Match&gt;<br />
&lt;Class name="~.*introspector\.Bean\d+" /&gt;<br />
&lt;Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/&gt;<br />
&lt;/Match&gt;</code></p>
<p>There are some test classes that don&#8217;t exactly follow good rules of programming when it comes to dealing with mutability. Since they are test classes, I don&#8217;t really care to fix them. Instead I set up the filter to match all classes in an <code>introspector</code> package named <code>Bean1</code>, <code>Bean2</code>, etc. Simple as can be!</p>
<p>If you aren&#8217;t using <a href="http://findbugs.sourceforge.net/index.html">FindBugs</a>, you should be. <a href="http://findbugs.sourceforge.net/index.html">Go check it out</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2007/08/29/findbugs-is-even-cooler-than-i-thought/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

