<?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>/home/nick &#187; Java</title>
	<atom:link href="http://whatwouldnickdo.com/wordpress/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://whatwouldnickdo.com/wordpress</link>
	<description>Discussions on Programming, Linux, and whatever else.</description>
	<lastBuildDate>Thu, 20 Aug 2009 16:20:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iBatis &#8211; Mapping Database NULL</title>
		<link>http://whatwouldnickdo.com/wordpress/491/ibatis-mapping-database-null/</link>
		<comments>http://whatwouldnickdo.com/wordpress/491/ibatis-mapping-database-null/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 00:49:14 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iBatis]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=491</guid>
		<description><![CDATA[iBatis is a framework used to map a SQL database to POJOs (Plain Old Java Objects).&#160; iBatis is one framework of many out there, others include Hibernate.&#160; Recently I&#8217;ve been tasked with a new webapp which will connect to a very old legacy database.&#160; One of the first things I decided to do was look [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ibatis.apache.org/">iBatis</a> is a framework used to map a SQL database to <a href="http://en.wikipedia.org/wiki/POJO">POJOs</a> (Plain Old Java Objects).&nbsp; iBatis is one framework of many out there, others include <a href="http://www.hibernate.org/">Hibernate</a>.&nbsp; Recently I&#8217;ve been tasked with a new webapp which will connect to a very old legacy database.&nbsp; One of the first things I decided to do was look through the database and figure out what data I needed, and then design and create java objects to hold said data.&nbsp; I chose iBatis for this particular project because I was dealing with a legacy database which I had little control over, and iBatis can give me the flexibility I need in case I need to write complex and specific SQL to construct my objects.&nbsp; <br />
<span id="more-491"></span><br />
<strong><span style="font-size: medium;">The issue:</span></strong><br />
One thing I noticed about the database was that there are NULLs littered everywhere, and using a default value for columns was barely used at all.&nbsp; So there are plenty of columns with a data type of <strong>int</strong>, <strong>float</strong> and <strong>bit</strong> (I&#8217;m using a MS SQL Server database) that have NULLs in there.&nbsp; Now, if I was recoding other applications that updated and inserted into these places, I would have checked data and inserted a default value, as well as maybe altering the column to allow no NULLs and set a default value, but I can&#8217;t do that.&nbsp; These tables I&#8217;m using will get mapped to a POJO, and of course I want the ints and booleans in the database mapped to ints and booleans in my POJO.&nbsp; But what happens if one of those database ints or booleans has a NULL?&nbsp; Well, java will try to set the int or boolean to a null (which can&#8217;t be done) and it throws an exception instead&#8230;an <strong>IllegalArgumentException</strong> to be exact.</p>
<p><strong><span style="font-size: medium;">The quick fix:</span></strong><br />
Going through the iBatis docs can sometimes be tedious.&nbsp; Fortunately, the solution is simple.&nbsp; If you open your xml file dealing with the object in question, and go to your <strong>resultMap</strong> element for the class, you&#8217;ll typically have a <strong>result</strong> element for each column you&#8217;re dealing with.&nbsp; Add an attribute called <strong>nullValue</strong> with a value to give the object in question in case a NULL is present.&nbsp; It&#8217;s that simple.&nbsp; </p>
<p><strong><span style="font-size: medium;">Here&#8217;s an example&#8230;</span></strong><br />
You have a table called Employee with several columns and create a POJO like below to hold that data:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Employee <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> login<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> authorityType<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> passwordExpired<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// ... constructors and setter/getter methods here...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
Let&#8217;s say that authorityType and passwordExpired were NULL values in the database.&nbsp; Adding the nullValue attribute to the xml file like so would solve your issue:</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;resultMap</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;EmployeeResult&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;Employee&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;id&quot;</span>              <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;id&quot;</span>                               <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;login&quot;</span>           <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;login&quot;</span>                            <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;password&quot;</span>        <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;password&quot;</span>                         <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;authorityType&quot;</span>   <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;authorityType&quot;</span>   <span style="color: #000066;">nullValue</span>=<span style="color: #ff0000;">&quot;1&quot;</span>    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;passwordExpired&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;passwordExpired&quot;</span> <span style="color: #000066;">nullValue</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resultMap<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/491/ibatis-mapping-database-null/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quick Tomcat https SSL Config</title>
		<link>http://whatwouldnickdo.com/wordpress/431/quick-tomcat-https-ssl-config/</link>
		<comments>http://whatwouldnickdo.com/wordpress/431/quick-tomcat-https-ssl-config/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 19:04:52 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[web-dev]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=431</guid>
		<description><![CDATA[Setting up your webapp to work with https and SSL encryption when using Tomcat is easier than most people think.  Here&#8217;s a very quick HOW-TO to get you up and running&#8230; The first thing you need to do is create a certificate.  If you&#8217;re unfamiliar with certificates or SSL you can look at some of [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up your webapp to work with <a href="http://en.wikipedia.org/wiki/Https">https and SSL encryption</a> when using <a href="http://tomcat.apache.org/">Tomcat</a> is easier than most people think.  Here&#8217;s a very quick HOW-TO to get you up and running&#8230;<br />
<span id="more-431"></span><br />
The first thing you need to do is create a <a href="http://en.wikipedia.org/wiki/Certificate_Authority">certificate</a>.  If you&#8217;re unfamiliar with certificates or SSL you can look at some of the following links to help school you:<br />
<a href="http://tldp.org/HOWTO/SSL-Certificates-HOWTO/x64.html">http://tldp.org/HOWTO/SSL-Certificates-HOWTO/x64.html</a><br />
<a href="http://www.ourshop.org/resources/ssl.html">http://www.ourshop.org/resources/ssl.html </a><br />
<a href="http://www.wisegeek.com/what-is-the-difference-between-http-and-https.htm">http://www.wisegeek.com/what-is-the-difference-between-http-and-https.htm</a></p>
<p><strong>Creating your certificate</strong></p>
<ul>
<li>Go to your JRE bin folder and there will be a file called &#8220;keytool&#8221;.</li>
<li>Type <strong>keytool -genkey -alias tomcat -keyalg RSA -keystore c:/.keystore</strong> The &#8220;keystore&#8221; parameter is optional.  It&#8217;s the location where the certificate keystore will be stored.  By default it will be stored in the current user&#8217;s home directory.</li>
<li>Upon executing, you will be prompted with a number of questions like name, location, organization, etc.  For name I recommend using the domain or if need be the machine name.</li>
</ul>
<p><strong>Modifying the server.xml file</strong></p>
<ul>
<li>Locate the server.xml in $CATALINA_HOME/conf/server.xml</li>
<li>Open it and look for a section dealing with the SSL Connector.  The section will look something like this:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">&lt;Connector </span>
<span style="color: #808080; font-style: italic;">           port=&quot;8443&quot; minProcessors=&quot;5&quot; maxProcessors=&quot;75&quot;</span>
<span style="color: #808080; font-style: italic;">           enableLookups=&quot;true&quot; disableUploadTimeout=&quot;true&quot;</span>
<span style="color: #808080; font-style: italic;">           acceptCount=&quot;100&quot; debug=&quot;0&quot; scheme=&quot;https&quot; secure=&quot;true&quot;;</span>
<span style="color: #808080; font-style: italic;">           clientAuth=&quot;false&quot; sslProtocol=&quot;TLS&quot;/&gt;</span>
<span style="color: #808080; font-style: italic;">--&gt;</span></pre></div></div>

<ul>
<li>Uncomment the block, and add in another attribute  for the keystore location.  We&#8217;ll add in <strong>keystoreFile=&#8221;c:\.keystore&#8221;</strong>, so when finished we&#8217;ll have:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Connector</span> </span>
<span style="color: #009900;">           <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;8443&quot;</span> <span style="color: #000066;">minProcessors</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">maxProcessors</span>=<span style="color: #ff0000;">&quot;75&quot;</span></span>
<span style="color: #009900;">           <span style="color: #000066;">enableLookups</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">disableUploadTimeout</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">           <span style="color: #000066;">acceptCount</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;https&quot;</span> <span style="color: #000066;">secure</span>=<span style="color: #ff0000;">&quot;true&quot;</span>;</span>
<span style="color: #009900;">           <span style="color: #000066;">clientAuth</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">sslProtocol</span>=<span style="color: #ff0000;">&quot;TLS&quot;</span> <span style="color: #000066;">keystoreFile</span>=<span style="color: #ff0000;">&quot;c:\.keystore&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>For full workings of server.xml refer to the <a href="http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html">apache site</a>.   </p>
<p>Last step is to restart Tomcat and point the browser to:<br />
<strong>https://localhost:8443 </strong><br />
Remember the <strong>https</strong> and it uses port 8443 by default which can be changed in the server.xml</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/431/quick-tomcat-https-ssl-config/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GWT Right-click Context Menu</title>
		<link>http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/</link>
		<comments>http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 01:12:27 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web-dev]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=370</guid>
		<description><![CDATA[The Google Web Toolkit has been out for a while now, and yet there is still basic functionality that is missing from the toolkit.  Don&#8217;t get me started on the lack of draggable/resizable columns for the FlexTable, because that&#8217;s a rant and a half.  Given that GWT&#8217;s event handling model isn&#8217;t bad, you&#8217;d think they&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> has been out for a while now, and yet there is still basic functionality that is missing from the toolkit.  Don&#8217;t get me started on the lack of draggable/resizable columns for the FlexTable, because that&#8217;s a rant and a half.  Given that GWT&#8217;s event handling model isn&#8217;t bad, you&#8217;d think they&#8217;d have included from the get-go the ability to handle right-clicks and bringing up a <a href="http://en.wikipedia.org/wiki/Context_menu">context menu or popup menu</a>.  Well, even with 1.6 on the doorstep it seems they forgot again or just don&#8217;t care.   Now some people will spout out &#8220;web apps don&#8217;t need or shouldn&#8217;t have right-clicks handled or context menus overridden&#8221;&#8230;&#8230;and for those I say STFU!  Web apps are used for more than just banking, news, forums and dare I say blogs.  The browser is becoming the new medium for running applications and just because an application is running in a browser doesn&#8217;t mean we should limit functionality.  That&#8217;s about as narrow minded as saying that we&#8217;ve only had one mouse button for this long, why add a second one?  Duh!</p>
<p>Anyway, enough with the blabbing.  I&#8217;ve put together a simple example to add a right click context menu and override the default browser context menu using GWT. <br />
<span id="more-370"></span><br />
In the box below you can try it out, right-click in there and you can demo it.</p>
<table>
<tr>
<td><iframe src="http://whatwouldnickdo.com/rightclickex/RightClickEx.html" width="300" frameborder="0" height="310">  &amp;amp;lt;p&amp;amp;gt;Your browser does not support iframes.&amp;amp;lt;/p&amp;amp;gt; </iframe></td>
<td>
</td>
</tr>
</table>
<p>In case the iframe doesn&#8217;t show up in your browser you can see and try the example <a href="http://whatwouldnickdo.com/rightclickex/RightClickEx.html">here</a>.<br />
Now here&#8217;s how it&#8217;s done.</p>
<p>I used a DeckPanel to switch between several panels. The popup context menu is used to choose.  To allow the DeckPanel to catch the right-click event (and you can also listen for double-clicks and several other things) I extended the DeckPanel.   For simplicity I added &#8220;Adv&#8221; (Advanced) in front of the several classes I&#8217;ve extended so this one will be <strong>AdvDeckPanel</strong>.  The first thing to do in the constructor is add <strong>sinkEvents()</strong>. Then we&#8217;ll override <strong>onBrowserEvent()</strong> in the class.  Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> AdvDeckPanel<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;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sinkEvents<span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span>.<span style="color: #006633;">ONMOUSEUP</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">ONDBLCLICK</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">ONCONTEXTMENU</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> onBrowserEvent<span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span> event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;onBrowserEvent&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  event.<span style="color: #006633;">cancelBubble</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><span style="color: #666666; font-style: italic;">//This will stop the event from being propagated</span>
  event.<span style="color: #006633;">preventDefault</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;">switch</span> <span style="color: #009900;">&#40;</span>DOM.<span style="color: #006633;">eventGetType</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">ONMOUSEUP</span><span style="color: #339933;">:</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DOM.<span style="color: #006633;">eventGetButton</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">BUTTON_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Event.BUTTON_LEFT&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        listener.<span style="color: #006633;">onClick</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, event<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;">if</span> <span style="color: #009900;">&#40;</span>DOM.<span style="color: #006633;">eventGetButton</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">BUTTON_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Event.BUTTON_RIGHT&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        listener.<span style="color: #006633;">onRightClick</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">ONDBLCLICK</span><span style="color: #339933;">:</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #003399;">Event</span>.<span style="color: #006633;">ONCONTEXTMENU</span><span style="color: #339933;">:</span>
      GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Event.ONCONTEXTMENU&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Do nothing</span>
  <span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//end switch</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice the two lines in onBrowserEvent():<br />
<strong> event.cancelBubble(true);<br />
event.preventDefault();</strong></p>
<p>These are the two lines that tell the browser not to show it&#8217;s default context popup menu.  Also note that overriding the default context menu doesn&#8217;t work in all browsers, I&#8217;m not sure if this is a bug in GWT.  If you&#8217;re using firefox then you&#8217;ll have no problems, with IE you may need to add the following to your html:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;body oncontextmenu=&quot;return false;&quot;&gt;</pre></div></div>

<p>Other than that there&#8217;s just a switch statement that checks the event type, in this case we&#8217;re interested with <strong>ONMOUSEUP</strong>, and we&#8217;ll call the listener&#8217;s <strong>onClick() </strong>or <strong>onRightClick()</strong> based on the Event&#8217;s fields.</p>
<p>AdvDeckPanel also has a reference to AdvClickListener which looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> AdvClickListener <span style="color: #000000; font-weight: bold;">extends</span> ClickListener <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>Widget sender, <span style="color: #003399;">Event</span> event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> onRightClick<span style="color: #009900;">&#40;</span>Widget sender, <span style="color: #003399;">Event</span> event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This reference is basically the same as ClickListener, but has a separate method to handle the right-click.  I also pass the <strong>Event</strong> object so I can get the x and y from the click so the context menu shows up at that location instead of the top-left of the screen.</p>
<p>AdvDeckPanel implements <strong>AdvClickNotifier</strong> which does the same thing as GWT&#8217;s <strong>SourcesClickEvents</strong> interface, but handles the <strong>AdvClickListener</strong> instead.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> AdvClickNotifier <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addClickListener<span style="color: #009900;">&#40;</span>AdvClickListener listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeClickListener<span style="color: #009900;">&#40;</span>AdvClickListener listener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, once you have your widget (in this case the AdvDeckPanel) and the listeners set up to handle the right-click, then we add in the code to build the popup menu and commands that go with it.  I put all of this in the <strong>EntryPoint</strong>.  I have three widgets (panels) and a <strong>Command</strong> for each like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> AdvDeckPanel deckPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AdvDeckPanel<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> <span style="color: #000000; font-weight: bold;">private</span> PopupPanel popupPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PopupPanel<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>
<span style="color: #000000; font-weight: bold;">private</span> VerticalPanel defaultPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VerticalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> SimplePanel imagePanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> SimplePanel sponserPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Command showAlertCommand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    deckPanel.<span style="color: #006633;">showWidget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    popupPanel.<span style="color: #006633;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hope this example helps.&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><span style="color: #339933;">;</span>
&nbsp;
Command showImageCommand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    deckPanel.<span style="color: #006633;">showWidget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    popupPanel.<span style="color: #006633;">hide</span><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><span style="color: #339933;">;</span>
&nbsp;
Command showSponserCommand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    deckPanel.<span style="color: #006633;">showWidget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    popupPanel.<span style="color: #006633;">hide</span><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><span style="color: #339933;">;</span></pre></div></div>

<p>A <strong>Command</strong> is called when the <strong>MenuItem</strong> is clicked.</p>
<p>Now the code to build the menu, link the commands, and handle the right-click:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> createPopupMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">MenuBar</span> popupMenuBar <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">MenuBar</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>
  <span style="color: #003399;">MenuItem</span> alertItem <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">MenuItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Show alert&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, showAlertCommand<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">MenuItem</span> imageItem <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">MenuItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Show Oliver &quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, showImageCommand<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">MenuItem</span> sponserItem <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">MenuItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Show sponser &quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, showSponserCommand<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  popupPanel.<span style="color: #006633;">setStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;popup&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  alertItem.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;popup-item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  imageItem.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;popup-item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sponserItem.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;popup-item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  popupMenuBar.<span style="color: #006633;">addItem</span><span style="color: #009900;">&#40;</span>alertItem<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  popupMenuBar.<span style="color: #006633;">addItem</span><span style="color: #009900;">&#40;</span>imageItem<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  popupMenuBar.<span style="color: #006633;">addItem</span><span style="color: #009900;">&#40;</span>sponserItem<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  popupMenuBar.<span style="color: #006633;">setVisible</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>
  popupPanel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>popupMenuBar<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> onRightClick<span style="color: #009900;">&#40;</span>Widget sender, <span style="color: #003399;">Event</span> event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> DOM.<span style="color: #006633;">eventGetClientX</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> DOM.<span style="color: #006633;">eventGetClientY</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  popupPanel.<span style="color: #006633;">setPopupPosition</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  popupPanel.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lastly, to make the menu actually look like a popup menu I modified the CSS like so:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.popup</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">gray</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">gray</span> <span style="color: #993333;">gray</span> <span style="color: #993333;">gray</span> <span style="color: #993333;">gray</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #933;">3px</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.popup-item</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">80</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>What this does is makes it so the border isn&#8217;t the thick default GWT blue, and uses a thin border with the right and bottom borders a bit thicker.  This gives the popup that shadowed look.</p>
<p>A couple of books worth checking out are: <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FGWT-Action-Easy-Google-Toolkit%2Fdp%2F1933988231%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1250784594%26sr%3D8-2&#038;tag=homenick-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">GWT in Action</a><img src="http://www.assoc-amazon.com/e/ir?t=homenick-20&#038;l=ur2&#038;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />and <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FGWT-Practice-Robert-Cooper%2Fdp%2F1933988290%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1250784594%26sr%3D8-1&#038;tag=homenick-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">GWT in Practice</a><img src="http://www.assoc-amazon.com/e/ir?t=homenick-20&#038;l=ur2&#038;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
<a href="http://whatwouldnickdo.com/wordpress/blog-attachments/right-click-gwt.7z">Here&#8217;s the source</a> and more links.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>GWT Yellow Fade Technique (YFT)</title>
		<link>http://whatwouldnickdo.com/wordpress/306/gwt-yellow-fade-technique-yft/</link>
		<comments>http://whatwouldnickdo.com/wordpress/306/gwt-yellow-fade-technique-yft/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 21:43:21 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web-dev]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=306</guid>
		<description><![CDATA[This is a quick example of a fading technique which notifies that a change or update in your GWT app has happened.&#160; Seems like every ajax site out there uses a technique similar to this to notify the user that something has happened.&#160; As I write this post, Google Docs flashes up a yellow &#8220;Saving&#8230;&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick example of a fading technique which notifies that a change or update in your <a href="http://code.google.com/webtoolkit/">GWT</a> app has happened.<span id="more-306"></span>&nbsp; Seems like every ajax site out there uses a technique similar to this to notify the user that something has happened.&nbsp; As I write this post, Google Docs flashes up a yellow &#8220;Saving&#8230;&#8221; box for a couple of seconds to let me know my document was automatically saved.&nbsp; This &#8220;Saving&#8230;&#8221; flash box functionality is actually something I was about to put into an application, so I did some searches to see what kind of information was out there.&nbsp; I found nothing on doing it in GWT, actually all you&#8217;ll see out there is a bunch of finger pointing and chest bashing about who came up with the technique first (who cares?).&nbsp; I put together a really fast example (which you can see and try below) and a handler that you can plug into your own app to accomplish the same thing.&nbsp;</p>
<p>
<iframe src="http://whatwouldnickdo.com/YFT/YellowFadeTech.html" width="300" frameborder="0" height="270">  &amp;amp;lt;p&amp;amp;gt;Your browser does not support iframes.&amp;amp;lt;/p&amp;amp;gt; </iframe><br />
In case the iframe doesn&#8217;t show up in your browser you can see and try the example <a href="http://whatwouldnickdo.com/YFT/YellowFadeTech.html">here</a>.<br />
<br />
First, let me explain how it&#8217;s all done.&nbsp; Using a list of colors, in this case different shades of yellow, you add and remove styles (a color) of a widget.&nbsp; The colors are stored in the CSS file.&nbsp; The change is triggered by a timer.&nbsp; The <b>YellowFadeHandler</b> class has an inner class called <b>FadeObject</b> which holds a color and a <b>com.google.gwt.user.client.ui.UIObject</b>. This UIObject is the super class of all major GWT widgets and has the methods:</p>
<pre><b>addStyleName</b>(java.lang.String&nbsp;style)
<span style="font-family: Verdana;">and</span>
<b>removeStyleName</b>(java.lang.String&nbsp;style)
</pre>
<p><strong>The FadeObject class</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> FadeObject <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> UIObject uiObj <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> color <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> FadeObject<span style="color: #009900;">&#40;</span>UIObject uiObj<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;">uiObj</span> <span style="color: #339933;">=</span> uiObj<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">uiObj</span>.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span>yftStyles<span style="color: #009900;">&#91;</span>color<span style="color: #009900;">&#93;</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> nextColor<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;">if</span> <span style="color: #009900;">&#40;</span>color <span style="color: #339933;">==</span> transparent_color<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
		uiObj.<span style="color: #006633;">removeStyleName</span><span style="color: #009900;">&#40;</span>yftStyles<span style="color: #009900;">&#91;</span>color<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		color<span style="color: #339933;">++;</span>
		uiObj.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span>yftStyles<span style="color: #009900;">&#91;</span>color<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getColor<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> color<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isTransparent<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;">if</span> <span style="color: #009900;">&#40;</span>color <span style="color: #339933;">==</span> transparent_color<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;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end class FadeObject</span></pre></div></div>

<p>
<strong>The YellowFadeHandler class</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>FadeObject<span style="color: #339933;">&gt;</span> fadeObjectList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedList<span style="color: #339933;">&lt;</span>FadeObject<span style="color: #339933;">&gt;</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;">public</span> YellowFadeHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Timer</span> t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Timer</span><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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<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;">if</span> <span style="color: #009900;">&#40;</span>fadeObjectList.<span style="color: #006633;">isEmpty</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: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Iterator<span style="color: #339933;">&lt;</span>FadeObject<span style="color: #339933;">&gt;</span> iter <span style="color: #339933;">=</span> fadeObjectList.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iter.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          FadeObject fObj <span style="color: #339933;">=</span> iter.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          fObj.<span style="color: #006633;">nextColor</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>fObj.<span style="color: #006633;">isTransparent</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;">//if it hits the transparent color then fading is done so remove it.</span>
            iter.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fade object removed&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    t.<span style="color: #006633;">scheduleRepeating</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">120</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> add<span style="color: #009900;">&#40;</span>UIObject obj<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>obj <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: #339933;">;</span>
    FadeObject fo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FadeObject<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fadeObjectList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, fo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fade object added&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>My YellowFadeHandler class holds a List of these FadeObjects.&nbsp; When the timer fires, it iterates through the list and changes (removes the old and adds the new) styles of the widgets.&nbsp; When the style is changed to the last color in the chain (transparent), the widget is then removed from the list.&nbsp; So to have a widget go through the yellow fade, all that needs to be done is call handler.add(widget);<br />
Super simple.  <a href="http://whatwouldnickdo.com/wordpress/blog-attachments/yft-test.7z">Here&#8217;s the source.</a><br />
A couple of books worth checking out are: <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FGWT-Action-Easy-Google-Toolkit%2Fdp%2F1933988231%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1250784594%26sr%3D8-2&#038;tag=homenick-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">GWT in Action</a><img src="http://www.assoc-amazon.com/e/ir?t=homenick-20&#038;l=ur2&#038;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />and <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FGWT-Practice-Robert-Cooper%2Fdp%2F1933988290%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1250784594%26sr%3D8-1&#038;tag=homenick-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">GWT in Practice</a><img src="http://www.assoc-amazon.com/e/ir?t=homenick-20&#038;l=ur2&#038;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/306/gwt-yellow-fade-technique-yft/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Inserting javascript into GWT using JSNI</title>
		<link>http://whatwouldnickdo.com/wordpress/294/inserting-javascript-into-gwt-using-jsni/</link>
		<comments>http://whatwouldnickdo.com/wordpress/294/inserting-javascript-into-gwt-using-jsni/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 01:01:44 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web-dev]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=294</guid>
		<description><![CDATA[Sure the whole point of using GWT is so you don&#8217;t have to mess with that abortion known as javascript, but sometimes you may need (or actually want) to use javascript for something in your GWT application.  For this we use JavaScript Native Interface (JSNI).  JSNI uses the native keyword, so if you&#8217;ve used JNI [...]]]></description>
			<content:encoded><![CDATA[<p>Sure the whole point of using <a id="bocv" title="GWT" href="http://code.google.com/webtoolkit/">GWT</a> is so you don&#8217;t have to mess with that abortion known as javascript, but sometimes you may need (or actually want) to use javascript for something in your GWT application.  For this we use <a id="qwkz" title="JavaScript Native Interface (JSNI)" href="http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;s=google-web-toolkit-doc-1-5&amp;t=DevGuideJavaScriptNativeInterface">JavaScript Native Interface (JSNI)</a>.  JSNI uses the <strong>native </strong>keyword, so if you&#8217;ve used <a id="j9bn" title="JNI" href="http://en.wikipedia.org/wiki/Java_Native_Interface">JNI</a> (Java Native Interface) in the past you&#8217;ll have little to get used to.</p>
<p>I needed to use JSNI recently.  Since GWT doesn&#8217;t provide a way to bring the browser to the front or top like javascript does with it&#8217;s <strong>self.focus();</strong> I was able to use JSNI to call that line of javascript.  Here&#8217;s a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> bringToFront<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
  self.focus();
}-*/</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then all you need to do is call the bringToFront() method like you normally would.  Along with noticing in the <strong>native </strong>keyword, you&#8217;ll immediate see that the block looks commented out.  JSNI has two tokens to mark the beginning and end of your javascript the <strong>/*-{</strong> marks the begin and <strong>}-*/</strong> marks the end.  Everything in between those tokens are assumed to be javascript.</p>
<p>There are more examples on <a id="w.ro" title="GWT JSNI site" href="http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;s=google-web-toolkit-doc-1-5&amp;t=DevGuideJavaScriptFromJava">GWT JSNI site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/294/inserting-javascript-into-gwt-using-jsni/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Charts in GWT with gchart</title>
		<link>http://whatwouldnickdo.com/wordpress/264/simple-charts-in-gwt-with-gchart/</link>
		<comments>http://whatwouldnickdo.com/wordpress/264/simple-charts-in-gwt-with-gchart/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 01:17:10 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=264</guid>
		<description><![CDATA[I&#8217;ve been tasked with adding some simple charts to a GWT project and after looking at several APIs I&#8217;ve settled with trying out gchart.  A couple of reasons for this choice is: gchart is 100% GWT (meaning it&#8217;s not a javascript wrapper) It runs on the client-side. Some other charting APIs actually build the chart [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tasked with adding some simple charts to a <a id="t8w3" title="GWT" href="http://code.google.com/webtoolkit/">GWT</a> project and after looking at several APIs I&#8217;ve settled with trying out <a id="bi4y" title="gchart" href="http://code.google.com/p/gchart/">gchart</a>.  A couple of reasons for this choice is:</p>
<ul>
<li>gchart is 100% GWT (meaning it&#8217;s not a javascript wrapper)</li>
<li>It runs on the client-side. Some other charting APIs actually build the chart on the server-side as an image and return the link for the image.  This can be an advantage for some situations, so you may need to think about if you want a client-side or server-side render.</li>
<li>Open source under <span>Apache License, Version 2.0</span></li>
<li>Very simple to use.</li>
</ul>
<p>I put together a very simple example, and it shows how quickly you can build a chart.  The example is a compound interest financial calculator shown below (go ahead and try it out).  It has a few fields to enter your initial amount, annual contributions, interest rate, number of compounds per year and the number of years.  After clicking on the calculate button it will show your future amount and chart it.</p>
<p><iframe frameborder="0" src ="http://whatwouldnickdo.com/CompoundInterest/RetCalc.html" width=440px" height="390px">
<p>Your browser does not support iframes.</p>
<p> </iframe><br />
In case the iframe doesn&#8217;t show up in your browser you can see and try the charting example <a href="http://whatwouldnickdo.com/CompoundInterest/RetCalc.html">here</a>.</p>
<p>The simplicity of this charting API is the fact that the charts are GWT widgets.  Here&#8217;s the code for my compounding interest chart:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AmountChart <span style="color: #000000; font-weight: bold;">extends</span> GChart <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> AmountChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		setChartSize<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">240</span>, <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setPadding<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;4px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		getXAxis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAxisLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Years&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		getYAxis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAxisLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;$&quot;</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> addPoint<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> x, <span style="color: #000066; font-weight: bold;">double</span> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		GWT.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;point added (&quot;</span><span style="color: #339933;">+</span>x<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #339933;">+</span>y<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;)&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		getCurve<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addPoint</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then all I did was add it to the DecoratedTabPanel, put in the event listeners, the <a href="http://en.wikipedia.org/wiki/Compound_interest">formula (which I got from wiki)</a> and done.<br />
You can download the full <a href="http://whatwouldnickdo.com/wordpress/blog-attachments/compoundinterest.7z">source here</a>, and the entire application is client side.</p>
<p><em><strong>Updated 2008-01-28:</strong> I updated the iframe that the form is in to be more friendly with IE.  Also made a change recommended by John Gunther to remedy a problem with IE.  Compiled using gchart 2.4 and I updated the downloadable source.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/264/simple-charts-in-gwt-with-gchart/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>GWT Hosted Mode and Log4j</title>
		<link>http://whatwouldnickdo.com/wordpress/186/gwt-hosted-mode-and-log4j/</link>
		<comments>http://whatwouldnickdo.com/wordpress/186/gwt-hosted-mode-and-log4j/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 01:53:02 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[web-dev]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=186</guid>
		<description><![CDATA[This is a short tutorial on getting log4j to run in the embedded Tomcat included with GWT.  Before I go on I need to say that log4j will only work on the server-side. GWT doesn&#8217;t support logging with log4j on the client side (yet&#8230;maybe). To log on the client side you&#8217;ll still have to use [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short tutorial on getting <a href="http://logging.apache.org/log4j/">log4j</a> to run in the embedded Tomcat included with <a href="http://code.google.com/webtoolkit/">GWT</a>.   Before I go on I need to say that log4j will only work on the server-side.  GWT doesn&#8217;t support logging with log4j on the client side (yet&#8230;maybe).  To log on the client side you&#8217;ll still have to use GWT.log()</p>
<p>There are four things we&#8217;ll need to accomplish:<br />
<a href="#log4j.properties">1.  Place the log4j.properties file</a><br />
<a href="#servlet">2.  Write a servlet that will initialize the logger.</a><br />
<a href="#web.xml">3.  Modify the web.xml file.</a><br />
<a href="#scripts">4.  Modify the GWT -shell and -compile scripts.</a></p>
<h4><big><a name="log4j.properties">1.  Place the log4j.properties file</a></big></h4>
<p>Under <strong>&lt;gwt-project&gt;/tomcat/webapps/ROOT/WEB-INF/</strong> create a “<strong>classes</strong>” dir.   The “classes” dir is where you put the log4j.properties file.  Here’s the log4j.properties file I’m using:<br />
<span style="font-family: Courier New;">log4j.rootCategory=DEBUG, dest1, dest3</span></p>
<p><span style="font-family: Courier New;">! Log to the console<br />
log4j.appender.dest1=org.apache.log4j.ConsoleAppender<br />
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout<br />
log4j.appender.dest1.layout.ConversionPattern=%-5p %d{HH:mm:ss.SSS} [%-15.15t] [%-25.25c{1}] %m%n</span></p>
<p><span style="font-family: Courier New;">! LOG TO A FILE<br />
log4j.appender.dest3=org.apache.log4j.RollingFileAppender<br />
log4j.appender.dest3.layout=org.apache.log4j.PatternLayout<br />
log4j.appender.dest3.layout.ConversionPattern=%-5p %d{EEE MMM dd HH:mm:ss.SSS zzz yyyy} [%-15.15t] [%-25.25c{1}] %m%n</span></p>
<p><span style="font-family: Courier New;">! Specify the file name<br />
log4j.appender.dest3.File=./logs/hosted-log4j.log</span></p>
<p><span style="font-family: Courier New;">! Control the maximum log file size<br />
log4j.appender.dest3.MaxFileSize=3000KB<br />
log4j.appender.dest3.MaxBackupIndex=3<br />
</span></p>
<h4><big><a name="servlet">2.  Write a servlet that will initialize the logger.</a></big></h4>
<p>Next you&#8217;ll want to have a servlet that will load the properties file and init the logger.  This file (<span style="font-family: &quot;Courier New&quot;; color: black;"><span style="font-size: x-small;">Log4JInitServlet.java</span></span>) will go in the <strong>&lt;gwt-project&gt;/src/</strong> dir.</p>

<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.nick.example.server</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServlet</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>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.PropertyConfigurator</span><span style="color: #339933;">;</span>
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Log4JInitServlet
*
* This class should get loaded first (based on the web.xml),
* so it can init the logger.
*
* @author Nick
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Log4JInitServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</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>Log4JInitServlet.<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> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <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;Log4JInitServlet init() starting.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> log4jfile <span style="color: #339933;">=</span> getInitParameter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;log4j-properties&quot;</span><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;log4jfile: &quot;</span><span style="color: #339933;">+</span>log4jfile<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>log4jfile <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span> propertiesFilename <span style="color: #339933;">=</span> getServletContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getRealPath</span><span style="color: #009900;">&#40;</span>log4jfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      PropertyConfigurator.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span>propertiesFilename<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;logger configured.&quot;</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;Error setting up logger.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</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;Log4JInitServlet init() done.&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></pre></div></div>

<p>This servlet should be loaded first, which can be accomplished by modifying the web.xml file.</p>
<h4><big><a name="web.xml">3.  Modify the web.xml file.</a></big></h4>
<p>This file is located in &lt;gwt-project&gt;/tomcat/webapps/ROOT/WEB-INF/<br />
My web.xml file looks like:</p>
<pre class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;Log4JInitServlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.nick.example.server.Log4JInitServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;log4j-properties&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/classes/log4j.properties&lt;/param-value&gt;
     &lt;/init-param&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;shell&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.google.gwt.dev.shell.GWTShellServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;shell&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
&lt;/web-app&gt;</pre>
<p>Notice the line <strong>&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;</strong>, which tells tomcat to load the Log4JInitServlet first.</p>
<h4><big><a name="scripts">4.  Modify the GWT -shell and -compile scripts.</a></big></h4>
<p>Modify your gwt –shell and –compile files to add the log4j jar into the class path.  Here’s my &lt;project&gt;-shell.cmd file.  Take note of the log4j jar that I added.</p>
<p>[Windows]<span style="font-family: Courier New;"><br />
@java -Xmx256M -cp &#8220;%~dp0\src;%~dp0\bin;C:/lib/gwt-windows-1.5.3/gwt-user.jar;C:/lib/gwt-windows-1.5.3/gwt-dev-windows.jar;C:/lib/gwt-windows-1.5.3/log4j-1.2.12.jar&#8221; com.google.gwt.dev.GWTShell -out &#8220;%~dp0\www&#8221; %* com.nick.example.HostedLog4j/HostedLog4j.html</span></p>
<p>[linux]<span style="font-family: Courier New;"><br />
#!/bin/sh<br />
APPDIR=`dirname $0`;<br />
java  -Xmx256M -cp &#8220;$APPDIR/src:$APPDIR/bin:$HOME/projects/gwt-linux-1.5.3/gwt-user.jar:$HOME/projects/gwt-linux-1.5.3/gwt-dev-linux.jar:$HOME/projects/lib/log4j-1.2.15.jar&#8221; com.google.gwt.dev.GWTShell -out &#8220;$APPDIR/www&#8221; &#8220;$@&#8221; com.nick.example.HostedLog4j/HostedLog4j.html;</span></p>
<p>Make sure to change the &lt;project&gt;-compile.cmd in the same way.<br />
You can then run your &lt;gwt-project&gt;-shell.cmd and the logger should work.   It will create a log directory in under &lt;gwt-project&gt; and place your log file inside there.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/186/gwt-hosted-mode-and-log4j/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GWT-Ext to Ext-GWT</title>
		<link>http://whatwouldnickdo.com/wordpress/235/gwt-ext-to-ext-gwt/</link>
		<comments>http://whatwouldnickdo.com/wordpress/235/gwt-ext-to-ext-gwt/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 02:32:02 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=235</guid>
		<description><![CDATA[Trying both GWT-Ext and Ext-GWT In trying to make a decision on whether to go GWT-Ext or Ext-GWT I&#8217;ve done some reading including the websites of those two technologies, forums, and various blogs like: http://www.gwtsite.com/top-5-gwt-libraries/ http://roberthanson.blogspot.com/2008/04/gwt-ext-vs-ext-gwt.html http://ajaxian.com/archives/to-gwt-ext-or-to-ext-gwt The most talked about topic when discussing this comparison seems to be licensing, but I don&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="font-size: medium;">Trying both GWT-Ext and Ext-GWT</span></strong></p>
<p>In trying to make a decision on whether to go <a id="mq_b" title="GWT-Ext" href="http://code.google.com/p/gwt-ext/">GWT-Ext</a> or <a id="mo35" title="Ext-GWT" href="http://extjs.com/products/gxt/">Ext-GWT</a> I&#8217;ve done some reading including the websites of those two technologies, forums, and various blogs like:</p>
<p><a id="qqpn" title="http://www.gwtsite.com/top-5-gwt-libraries/" href="http://www.gwtsite.com/top-5-gwt-libraries/">http://www.gwtsite.com/top-5-gwt-libraries/</a><br />
<a id="j9cf" title="http://roberthanson.blogspot.com/2008/04/gwt-ext-vs-ext-gwt.html" href="http://roberthanson.blogspot.com/2008/04/gwt-ext-vs-ext-gwt.html">http://roberthanson.blogspot.com/2008/04/gwt-ext-vs-ext-gwt.html</a><br />
<a id="k2zz" title="http://ajaxian.com/archives/to-gwt-ext-or-to-ext-gwt" href="http://ajaxian.com/archives/to-gwt-ext-or-to-ext-gwt">http://ajaxian.com/archives/to-gwt-ext-or-to-ext-gwt</a></p>
<p>The most talked about topic when discussing this comparison seems to be licensing, but I don&#8217;t want to spend much time on that.  Instead of comparing the two technologies line by line, I take a small existing vanilla <a id="tity" title="GWT" href="http://code.google.com/webtoolkit/">GWT</a> application and add new needed functionality such as drag and drop, resizable columns, sortable columns, and additional layouts.  This was done first using GWT-Ext and then again using Ext-GWT.  The opinions I gather are based on coding with both over a few days.</p>
<p><strong><span style="font-size: medium;">GWT-Ext Experience</span></strong></p>
<p>This was actually my second choice, and became my first choice based on comparing the licenses of the two.  My first steps were changing out widgets used and hoping that the underlying code dealing with the model wouldn&#8217;t need to be modified (much).  Layouts are one thing I noticed that are considerably different.  Instead of using VerticalPanel or HorizontalPanel, you use a Panel and add a modifier to make it flow vertical or horizontal, much like Swing.  While this is good if you know Swing, and are starting the app from scratch, it can be a pain if converting like i am.</p>
<p>Another difference when dealing with going vanilla GWT to GWT-Ext was rewriting code that handles FlexTable or GridPanel updates or, in other words, the way you get data into the table.  In GWT land, you can treat the FlexTable as the data, much like a two-dim array, and set data to the cells.  GWT-Ext uses something called a Store, which is basically the data itself.  When you add to the Store, the GridPanel gets updated.  There are pros and cons to both methods I suppose, but that&#8217;s another discussion.  I will say the reason I stopped using GWT-Ext was because of problems rendering the grid to the screen when using the GridPanel with certain layouts.  I suspected this was due to it being a js wrapper.  It turned out there was a known bug which required a workaround just to get the grid to show.  After spending many hours dealing with this problem and a few others I decided I shouldn&#8217;t be wasting my time with something that has problems taking one panel and adding it to another like panel.add(grid).  In GUI building, an operation like that is simple and frequent.</p>
<p><strong><span style="font-size: medium;">On to Ext-GWT</span></strong></p>
<p>Last thing I wanted to do was revert back and start again, but here it goes.</p>
<p>One big difference between the two Exts is that GWT-Ext is just javascript wrapper.  It&#8217;s visible while configuring because you&#8217;ll add scripts and javascript  libraries to your public folder.  With Ext-GWT none of that needed to be done.  This is because Ext-GWT is a GWT library and doesn&#8217;t wrap javascript.  I like this.<br />
<iframe src="http://rcm.amazon.com/e/cm?t=homenick-20&#038;o=1&#038;p=13&#038;l=st1&#038;mode=books&#038;search=GWT%20in%20action&#038;fc1=000000&#038;lt1=&#038;lc1=3366FF&#038;bg1=FFFFFF&#038;f=ifr" marginwidth="0" marginheight="0" width="468" height="60" border="0" frameborder="0" style="border:none;" scrolling="no"></iframe><br />
So I start again changing out widgets, and notice that there&#8217;s almost no work to be done.  The new widgets use same function calls as old ones.  They did drop the ball on the Button class and it&#8217;s listener (actually, I don&#8217;t like the way events are coded).  Not sure why you would not stick with a ClickListener and onClick()&#8230;.but whatever.   The layouts are similar, and they include VerticalPanel as well.  Changing the FlexTable out for the Grid took some work, but less than GWT-Ext.  It does use a StoreList (similar to GWT-Ext&#8217;s Store) but I felt it made a little more sense.  There was little time spent correcting column sizes and dealing with autofills, which makes me happy, and there were no issues getting the Grid to show up.</p>
<p><strong><span style="font-size: medium;">Final Decision</span></strong></p>
<p>Well, everything was fine but another day has passed and I&#8217;m just not 100% happy with Ext-GWT.  Running the hosted browser and compiling has become slower than ever (still faster than GWT-Ext though).  I got to thinking and realized that the only enhanced component I really <strong>needed </strong>was the Grid over the FlexTable, and I did get the grid setup just like I wanted.  Since one of the things I really hated about Ext-GWT was the event handling code, I asked myself: Do I really need to have all of my buttons, checkboxes, panels, etc in Ext-GWT?  Can&#8217;t I just use the fancy Grid and then make everything else using vanilla GWT?  I decided to try this, and not only did it work perfectly, but there was noticably lower load times and increased speed.</p>
<p>My final take is, use vanilla GWT for events and where you <strong>can </strong>use it.  For GWT components that are missing features you need use Ext-GWT.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/235/gwt-ext-to-ext-gwt/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Java EchoServer Example</title>
		<link>http://whatwouldnickdo.com/wordpress/216/java-echoserver-example/</link>
		<comments>http://whatwouldnickdo.com/wordpress/216/java-echoserver-example/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 03:27:36 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=216</guid>
		<description><![CDATA[I&#8217;m using this post to experiment with syntax highlighting in my blog.  Recently a friend needed a program to echo data on a socket while he was testing an internet appliance and some other network enabled hardware so I figured I&#8217;d just use that code as my example. The EchoServer will open a listen socket [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using this post to experiment with syntax highlighting in my blog.  Recently a friend needed a program to echo data on a socket while he was testing an internet appliance and some other network enabled hardware so I figured I&#8217;d just use that code as my example.</p>
<p>The EchoServer will open a listen socket on port 4444.  Compile it, run it and then to test it you can open a command prompt and type <strong>telnet localhost 4444</strong></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;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.OutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.ServerSocket</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.Socket</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author NickC
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EchoServer <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> <span style="color: #000066; font-weight: bold;">int</span> BUFFER_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">256</span><span style="color: #339933;">;</span> 
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> listenPort <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4444</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">ServerSocket</span> serverSock <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ServerSocket</span><span style="color: #009900;">&#40;</span>listenPort<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;listening on port &quot;</span><span style="color: #339933;">+</span>listenPort<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">Socket</span> sock <span style="color: #339933;">=</span> serverSock.<span style="color: #006633;">accept</span><span style="color: #009900;">&#40;</span><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;new connection &quot;</span> <span style="color: #339933;">+</span> sock<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003399;">InputStream</span> sockIn <span style="color: #339933;">=</span> sock.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">OutputStream</span> sockOut <span style="color: #339933;">=</span> sock.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span>BUFFER_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">while</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: #009900;">&#123;</span>
         <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>count <span style="color: #339933;">=</span> sockIn.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><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>count <span style="color: #339933;">&gt;=</span> buffer.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               count <span style="color: #339933;">=</span> buffer.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            count <span style="color: #339933;">=</span>  sockIn.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span>buffer, <span style="color: #cc66cc;">0</span>, count<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;echoing &quot;</span><span style="color: #339933;">+</span>count<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; bytes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sockOut.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>buffer, <span style="color: #cc66cc;">0</span>, count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sockOut.<span style="color: #006633;">flush</span><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>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Source in a file: <a href="http://www.whatwouldnickdo.com/wordpress/blog-attachments/EchoServer.java">EchoServer.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/216/java-echoserver-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tomcat Images Directory</title>
		<link>http://whatwouldnickdo.com/wordpress/157/tomcat-images-directory/</link>
		<comments>http://whatwouldnickdo.com/wordpress/157/tomcat-images-directory/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 04:11:03 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[web-dev]]></category>

		<guid isPermaLink="false">http://whatwouldnickdo.com/wordpress/?p=157</guid>
		<description><![CDATA[A short rundown on adding external directories to your Apache Tomcat webapp path. I started with a simple problem and it turns out there&#8217;s a simple solution. My problem: In the current application I&#8217;m coding I display user data (like many apps).  Included with the user data, the page also shows the user&#8217;s photo.  The [...]]]></description>
			<content:encoded><![CDATA[<p>A short rundown on adding external directories to your <a href="http://tomcat.apache.org/">Apache Tomcat</a> webapp path.</p>
<p>I started with a simple problem and it turns out there&#8217;s a simple solution.</p>
<p><span style="text-decoration: underline;">My problem:</span><br />
In the current application I&#8217;m coding I display user data (like many apps).  Included with the user data, the page also shows the user&#8217;s photo.  The problem was that the photos were stored in a directory external to Tomcat (D:\photos) and I need to get my webapp access to that directory and have those photos in Tomcat&#8217;s path.</p>
<p><span style="text-decoration: underline;">My Solution:</span><br />
To solve this I needed to add what Apache calls a context path which can be done by adding an xml file.</p>
<p><span style="text-decoration: underline;">Here&#8217;s a bit of given information so this is easier to follow.</span></p>
<ul>
<li>I&#8217;m using Tomcat 5.5</li>
<li>The name of my webapp is called <strong>MyProject</strong> which is located at <strong>$CATALINA_HOME/webapps/MyProject</strong></li>
<li>The directory I&#8217;m trying to add to Tomcat&#8217;s path is &#8220;<strong>D:\photos</strong>&#8220;</li>
<li>I want my photos to be accessible in the path<strong> $CATALINA_HOME/webapps/MyProject/photos</strong> (or http://localhost:8080/MyProject/photos).</li>
</ul>
<p><span style="text-decoration: underline;">Creating the context file:</span></p>
<ul>
<li>In $CATALINA_HOME/conf/[enginename]/[hostname]/ (in my case $CATALINA_HOME/conf/Catalina/localhost/) create a file called &#8220;<strong>MyProject#photos.xml</strong>&#8220;.  The value before the # is your webapp name and the value after is the path you want added.</li>
<li>In this file add: <strong>&lt;Context docBase=&#8221;d:\photos&#8221; /&gt;</strong> and save.</li>
<li>Restart Tomcat.</li>
</ul>
<p>Note for GWT:  I can&#8217;t seem to get this working with the embedded Tomcat that comes with GWT.  If anyone knows a simply way, please let me know.  In the mean time I&#8217;m using full Tomcat with the noserver option, and for the name of my context file I&#8217;m putting the full package name.  For example: com.nick.MyProject#photos.xml</p>
]]></content:encoded>
			<wfw:commentRss>http://whatwouldnickdo.com/wordpress/157/tomcat-images-directory/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
