<?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; Development</title>
	<atom:link href="http://www.megatome.com/tag/development/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>Moving to Agile: Inertia</title>
		<link>http://www.megatome.com/2008/12/10/moving-to-agile-inertia/</link>
		<comments>http://www.megatome.com/2008/12/10/moving-to-agile-inertia/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 03:49:23 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[leadership]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[inertia]]></category>
		<category><![CDATA[scrum]]></category>

		<guid isPermaLink="false">http://www.megatome.com/?p=48</guid>
		<description><![CDATA[Switching to an Agile process shines the light on a developer who has been successfully hiding his lack of work, but what can I do to change his behavior?]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been given the dubious honor of leading a team using Scrum as a &#8220;pilot&#8221; to see how well it works for the company. I&#8217;ve used Scrum before and had a good amount of success, so I feel comfortable with the process.</p>
<p>The single largest variable on any development team is the developers. I&#8217;ve found that moving to an Agile process like Scrum can really expose developers who&#8217;ve been hiding behind &#8220;traditional&#8221; processes.</p>
<p>Therein lies one of the biggest problems I&#8217;ve run into. One of my developers is not what you could by any means call a self starter. He has been able to get along well with the official process, which does not do a good job of tracking what developers are working on. Now that he&#8217;s been thrown into Scrum, it&#8217;s become quite obvious that he really doesn&#8217;t do anything until somebody nags him long enough to get him going.</p>
<p>This is where inertia comes in. This developer is a textbook example of an object staying at rest until the team lead can poke and prod enough to finally get him moving. His previous lead had simply taken it as granted that he would have to spend a certain amount of time micromanaging to get any work out of the developer. I think it&#8217;s a waste of time and energy for me to constantly remind him to pick a task and work it, but that&#8217;s what I&#8217;ve been reduced to doing. This week, for example, it took two days of nagging to get him to perform a ten minute refactor. (I would have done the refactor myself, but I have to trust that my team can do their jobs, too.)</p>
<p>I don&#8217;t know how to engage this guy. I can spend time collecting data and create metrics, but I don&#8217;t think that&#8217;s an effective motivator. What I&#8217;d really like to see is a commitment to the team and to the project that leads into a desire to pull his fair share. I don&#8217;t even know if these are feelings I can engender in this developer.</p>
<p>Motivation is an issue for teams using any kind of development process. Every team member reacts differently to various inputs. Some members like recognition, while others prefer a bonus. Some just want to be left alone so they can do the bare minimum to get by. I&#8217;m hoping this isn&#8217;t the eventual outcome with this developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2008/12/10/moving-to-agile-inertia/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Is Refactoring Really That Scary?</title>
		<link>http://www.megatome.com/2008/03/27/is-refactoring-really-that-scary/</link>
		<comments>http://www.megatome.com/2008/03/27/is-refactoring-really-that-scary/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 03:45:08 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[leadership]]></category>
		<category><![CDATA[Making]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.megatome.com/2008/03/27/is-refactoring-really-that-scary/</guid>
		<description><![CDATA[I got admonished at my new job for coding practices that have become second nature to me. Is aggressive refactoring really that scary?]]></description>
			<content:encoded><![CDATA[<div class="floatleft"><a href="http://www.cafepress.com/agilestuff.26911153"><img src="http://images.cafepress.com/product/26911153_240x240_Front_Color-BlackWhite.jpg" alt="Born to Refactor Shirt"/>
<p>(Click to get the shirt)</p>
<p></a></div>
<p>I&#8217;ve been coding with an agile mindset for quite some time now. Some practices have become second nature to me over the years. One of these practices is aggressive code refactoring, coupled with test driven development (TDD).</p>
<p>I&#8217;ve been adding new functionality to our system at my new job, and as usual I&#8217;ve been following my standard techniques. My part of the system involves handling certain requests and responses. I wrote unit and functional tests for the request half of the equation, then began to tackle the response side. As I added (and tested) functionality, I began to notice a large amount of similarity in the code. This in turn led me to create an abstract base class for both request and response, pulling up all of the shared functionality. This resulted in the actual request and response classes being quite small, with just a few method implementations from the base class.</p>
<p>So far, this activity should seem pretty normal to most developers. As I said, it&#8217;s pretty much second nature for me, and I don&#8217;t even remember consciously making the decision to make the abstract class. Imagine my surprise when my team lead admonished me for creating and abstract class, and warned me not to do it again without explicit approval.</p>
<p>Of course I had to ask why we would not refactor code in this manner when the opportunity presented itself. My lead&#8217;s answer involved several parts, none of which have convinced me that refactoring is bad:</p>
<p>
<ol>
<li><strong>The abstract class is not consistent with the rest of the system.</strong> This, to me, seems to be a fault of the system. I&#8217;m not knocking consistency, but at some point you have to realize that you may be building something that&#8217;s consistently bloated/overcomplicated/etc.</li>
<li><strong>The abstract class changes the design.</strong> Huh? Sure, if I go generate a UML diagram of the system, there&#8217;s going to be this abstract class and inheritance there. This is the only place the design is different. Requests and responses are being correctly handled just like the legacy ones in the system.</li>
<li><strong>Too much refactoring is bad, and each case should be thoroughly examined before code is changed.</strong> This is how religious wars start. My lead claims that developers start out on the &#8220;no refactoring&#8221; end of the spectrum, simply because they don&#8217;t know any better. Once they learn about refactoring, they then swing to the &#8220;refactor everything&#8221; end of the spectrum where anything and everything is a potential target. Seasoned, knowledgeable developers fall somewhere in the middle. I got the impression from this speech that my lead considers me to be on the radical end of the spectrum.</li>
</ol>
<p>Why are people like my lead so scared of refactoring? The arguments given really seem more like rationalizations than actual reasons &#8211; they don&#8217;t really stand up to scrutiny. I have a hard time believing, for example, that my lead truly thinks that the system is better because each request and response is a totally separate class, albeit with most of the code copied and pasted from one to the other. If anything, he should know that this approach leads to more problems, no matter how pretty it keeps the class diagrams.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2008/03/27/is-refactoring-really-that-scary/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JUnit Just Wants To Be Your Friend</title>
		<link>http://www.megatome.com/2008/03/14/junit-just-wants-to-be-your-friend/</link>
		<comments>http://www.megatome.com/2008/03/14/junit-just-wants-to-be-your-friend/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 03:02:57 +0000</pubDate>
		<dc:creator>iamthechad</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit tests]]></category>

		<guid isPermaLink="false">http://www.megatome.com/2008/03/14/junit-just-wants-to-be-your-friend/</guid>
		<description><![CDATA[My co-worker tests his code with the toString() and visual grep method. I'm not sure he would have ever caught the bug on his own. I keep trying to explain that unit tests are a Good Thing...]]></description>
			<content:encoded><![CDATA[<p>This is why you&#8217;re not allowed to have alcohol in the workplace.</p>
<p><strong>Co-Worker (who does not believe in unit tests)</strong>: Okay. I just checked my changes in.</p>
<p><strong>Me</strong>: There&#8217;s a bug in your code.</p>
<p><strong>Co-Worker</strong>: How do you know? I just checked it in!</p>
<p><strong>Me</strong>: It broke my unit tests. It looks like you&#8217;re not setting the flibbergibbet value correctly.</p>
<p><strong>Co-Worker</strong>: What? How can you tell?</p>
<p><strong>Me</strong>: <a href="http://www.junit.org/">JUnit</a> showed me the difference.</p>
<p><strong>Co-Worker</strong>: Oh. I guess I&#8217;ll fix it now. I would have found it eventually&#8230;</p>
<p>For what it&#8217;s worth, we&#8217;re handling <a href="http://en.wikipedia.org/wiki/Electronic_Data_Interchange">Electronic Data Interchange</a> documents &#8211; things that look like a page or so of line noise at a time. The bug was that one character wasn&#8217;t getting written to the output. My co-worker tests his code with the <code>toString()</code> and <a href="http://catb.org/jargon/html/V/vgrep.html">visual grep</a> method. I&#8217;m not sure he would have ever caught the bug on his own. I keep trying to explain that unit tests are a <a href="http://catb.org/jargon/html/G/Good-Thing.html">Good Thing</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.megatome.com/2008/03/14/junit-just-wants-to-be-your-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

