<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Darwin&#039;s Theories - Web category</title>
  <link>http://theories.darwinsys.com:80/categories/web/</link>
  <description>Call it a Blog if you like -- Ian</description>
  <language>en</language>
  <copyright>Ian Darwin</copyright>
  <lastBuildDate>Sun, 28 Feb 2010 01:08:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Site Modernization</title>
    <link>http://theories.darwinsys.com:80/2009/03/26/1238078940000.html</link>
    
      
        <description>
          Every web site needs to keep improving, and your obd&#039;t servant is no different. I started almost exactly a year ago 
&lt;a href=&#034;http://theories.darwinsys.com/2007/03/23/1174700820000.html&#034;&gt;
by replacing the old blog software with Pebble&lt;/a&gt;.
Then I got busy with real work, and had to put aside site maintenance. 
Around the beginning of this year I was able to modernize both the home page of 
&lt;a href=&#039;http://www.darwinsys.com&#039;&gt;darwinsys.com&lt;/a&gt;
(making it new and graphical) and the layout of 
&lt;a href=&#039;http://www.darwinsys.com/indextxt.jsp&#039;&gt;
the rest of the main site&lt;/a&gt;.
This week, I re-did the 
&lt;a href=&#039;http://www.darwinsys.com/jwf/&#039;&gt;
Java Web Frameworks&lt;/a&gt; site, which has gone from coyote-ugly to fairly modern looking, after being re-implemented using 
&lt;a href=&#039;http://www.seamframework.org/&#039;&gt;the Seam framework&lt;/a&gt;.
So, I am now running Seam (&amp;quot;war deployment&amp;quot; option) on Tomcat in production.&lt;br /&gt;
&lt;br /&gt;
At the same time, I had to upgrade 
&lt;a href=&#034;http://tomcat.apache.org/&#034;&gt;
the Tomcat web server&lt;/a&gt; from 5.5 to 6.0, which went fairly smoothly,
although there may be a few little bits that need a boost.
        </description>
      
      
    
    
    
    <category>Open Source Software</category>
    
    <category>Web</category>
    
    <comments>http://theories.darwinsys.com:80/2009/03/26/1238078940000.html#comments</comments>
    <guid isPermaLink="true">http://theories.darwinsys.com:80/2009/03/26/1238078940000.html</guid>
    <pubDate>Thu, 26 Mar 2009 14:49:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Using Java enums properly in Seam</title>
    <link>http://theories.darwinsys.com:80/2009/01/27/1233094920000.html</link>
    
      
        <description>
          The &lt;a href=&#034;http://www.seamframework.org/&#034;&gt;Seam&lt;/a&gt; documentation covers this now, but it&#039;s a bit short of complete examples. Most of this probably applies to other JSF/JPA deployments too (but please don&#039;t ask me how). To make the list of a given enum&#039;s values available to the view,&amp;nbsp; just add one new annotated method to a &amp;quot;Factories&amp;quot; class. &lt;br /&gt;
&lt;br /&gt;
@Name(&amp;quot;factories&amp;quot;)&lt;br /&gt;
public class Factories {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Factory(&amp;quot;countries&amp;quot;) &lt;br /&gt;
&amp;nbsp; &amp;nbsp; public Country[] getCountries() { &lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; return Country.values(); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
Because you want to display a user-friendly name in the web form, but store a short and consistent name in the database, the enum must have a &amp;quot;label&amp;quot; or &amp;quot;name&amp;quot; field and a getter method (many enums already do). For example, we&#039;ll display Canada in the drop-down but enter the ISO-3166 country code CA in the database.&lt;br /&gt;
&lt;br /&gt;
/** See ISO-3166 */&lt;br /&gt;
public enum Country { &lt;br /&gt;
&amp;nbsp;&amp;nbsp; CA(&amp;quot;Canada&amp;quot;), &lt;br /&gt;
&amp;nbsp;&amp;nbsp; US(&amp;quot;United States&amp;quot;), &lt;br /&gt;
&amp;nbsp;&amp;nbsp; AF(&amp;quot;Afghanistan&amp;quot;), &lt;br /&gt;
&amp;nbsp;&amp;nbsp; ... &lt;br /&gt;
&amp;nbsp;&amp;nbsp; ; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; private String longName; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; private Country(String longName) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.longName = longName; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp;&amp;nbsp; public String getLongName() { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return longName; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&amp;nbsp;  &amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; @Override &lt;br /&gt;
&amp;nbsp;&amp;nbsp; public String toString () { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getLongName(); &lt;br /&gt;
&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
You typically want to save the string name rather than the ordinal value into the database (especially with Countries where the list order  will change in future as countries split or join!) the @Entity class must be annotated  thusly: &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; @Column(name=&amp;quot;Country&amp;quot;) &lt;br /&gt;
&amp;nbsp;&amp;nbsp; @Enumerated(EnumType.STRING)&amp;nbsp;&amp;nbsp; // default and only other choice is  ORDINAL &lt;br /&gt;
&amp;nbsp;&amp;nbsp; public Country getCountry() { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return this.country; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
Then, to select it (display a drop-down), you&#039;d use, for example: &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;h:selectOneMenu  value=&amp;quot;#{register.personalAddress.country}&amp;quot;&amp;gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;s:selectItems var=&amp;quot;country&amp;quot;  value=&amp;quot;#{countries}&amp;quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label=&amp;quot;#{country.longName}&amp;quot;  noSelectionLabel=&amp;quot;-- Select --&amp;quot;/&amp;gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;s:convertEnum/&amp;gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/h:selectOneMenu&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If you&#039;ve used another framework than Seam, there&#039;s a bit of Seam&#039;s beauty: the Seam convertEnum tag fixes the &#039;orrible mess of having your data classes be required to know about UIComponent (can nobody on the JSF standards committee spell &amp;quot;tier violation&amp;quot;?).&lt;br /&gt;
&lt;br /&gt;
To display the current value in a view-only page,&amp;nbsp; you just need, for example, &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;h:outputText id=&amp;quot;country&amp;quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value=&amp;quot;#{person.personalAddress.country.longName}&amp;quot;/ &amp;gt; &lt;br /&gt;
&lt;br /&gt;
The data must be basically spotless for the enum converter to work, so - if you didn&#039;t have enumerating check constraints on the database from day one - you may e.g., have to &amp;quot;sanitize&amp;quot; the data a little to ensure  there are no non-null but blank&lt;strong class=&#034;moz-txt-star&#034;&gt;&lt;span class=&#034;moz-txt-tag&#034;&gt;&lt;/span&gt;&lt;/strong&gt; values in the database, or convert any lower-case values to upper case to match the enum constants. If not you&#039;ll get strange message like the famous &amp;quot;can&#039;t find resultList&amp;quot; - always check the JBoss console log for a stack trace!&lt;br /&gt;
&lt;br /&gt;
These can be cleaned with SQL like this, using whatever tool you use to feed raw SQL into whatever database you&#039;re using:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; update address set country = &#039;CA&#039; where country = &#039;&#039; &lt;br /&gt;
Or you could set these values to NULL.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; update address set country = upper(country) &lt;br /&gt;
&lt;br /&gt;
To check the values, you can use SQL similar to this:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct(country) from address&lt;br /&gt;
&lt;br /&gt;
Then it all works nicely, as it should, without any need for EntityConverter or for mixing UIComponents into your data layer. Seam rocks!
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <category>Web</category>
    
    <comments>http://theories.darwinsys.com:80/2009/01/27/1233094920000.html#comments</comments>
    <guid isPermaLink="true">http://theories.darwinsys.com:80/2009/01/27/1233094920000.html</guid>
    <pubDate>Tue, 27 Jan 2009 22:22:00 GMT</pubDate>
  </item>
  
  <item>
    <title>A Pox Upon all of your getMessage() calls</title>
    <link>http://theories.darwinsys.com:80/2009/01/19/1232387640000.html</link>
    
      
        <description>
          If you&#039;re not a Java programmer, you might as well run along to the next blog entry below. If you are, how often have you seen - or tolerated - code like this in a library you&#039;re using?&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clazz= Class.forName(className);&lt;br /&gt;
} catch (ClassNotFoundException e) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; throw new IllegalStateException(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
What&#039;s really wrong with this code is that it &lt;strong&gt;loses information&lt;/strong&gt;. The fact that the class requested could not be found is completely obliterated, wasting hours and hours of time amongst all the people who use the API. If the class name is org.foo.Foo, the only message the user gets is:&lt;br /&gt;
&lt;br /&gt;
IllegalStateException: org.foo.Foo&lt;br /&gt;
&lt;br /&gt;
What the user would like to see is something like this:&lt;br /&gt;
&lt;br /&gt;
IllegalStateException: ClassNotFoundException: org.foo.Foo&lt;br /&gt;
&lt;br /&gt;
Unlike the former, that is actually useful, and tells you how to track down the problem. And without having to download, accept licenses on, build a project around, etc., etc. the offending library.&lt;br /&gt;
&lt;br /&gt;
What&#039;s even more galling is that all the library maintainer needed to do is write the &amp;quot;throw&amp;quot; line as:&lt;br /&gt;
&lt;br /&gt;
throw new IllegalStateException(e.toString());&lt;br /&gt;
&lt;br /&gt;
You know, the offending version of the code above is only one rung up the latter to hell from code like this:&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // something here&lt;br /&gt;
} catch (Exception e) {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
That is, code that &amp;quot;swallows&amp;quot; an exception. Believe me, in my adventures with &lt;a href=&#034;http://www.darwinsys.com/jwf/&#034;&gt;numerous web development toolkits&lt;/a&gt;, I&#039;ve seen all of these. And reported them.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Folks, there&#039;s nothing like good error reporting. And this is nothing like good error reporting. Neither, in fact, is any stack trace that the user gets to see, but that&#039;s a topic for a later post.
        </description>
      
      
    
    
    
    <category>Software Industry</category>
    
    <category>Open Source Software</category>
    
    <category>Java</category>
    
    <category>Web</category>
    
    <comments>http://theories.darwinsys.com:80/2009/01/19/1232387640000.html#comments</comments>
    <guid isPermaLink="true">http://theories.darwinsys.com:80/2009/01/19/1232387640000.html</guid>
    <pubDate>Mon, 19 Jan 2009 17:54:00 GMT</pubDate>
  </item>
  
  <item>
    <title>JavaFX: Late to the gate, but sweet</title>
    <link>http://theories.darwinsys.com:80/2008/12/27/1230396568312.html</link>
    
      
        <description>
          &lt;a href=&#034;http://www.javafx.com/&#034;&gt;JavaFX&lt;/a&gt; is &lt;a href=&#034;http://www.sun.com/&#034;&gt;Sun&lt;/a&gt;&#039;s new Rich Client strategy for Java. If you haven&#039;t seen it yet, check out the demos on the &lt;a href=&#034;http://www.javafx.com/&#034;&gt;JavaFX home page&lt;/a&gt;. Unlike Adobe Flash and unlike M$ Silverlight, this technology actually works on &amp;quot;minority&amp;quot; OSes - my &lt;a href=&#034;http://www.openbsd.org/&#034;&gt;OpenBSD&lt;/a&gt; laptop with Java 1.6.0 is officially way behind the requirements, but the demos mostly work in FireFox 3 (except you can&#039;t tear off the tear-off applet, that requires Update 10). Despite &lt;em&gt;significant&lt;/em&gt; glitches on the web site - Sun should know better - on the day of the announcement (December 4, 2008), &lt;strong&gt;I&#039;m impressed&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
So much so that I&#039;ve already added &lt;a href=&#034;http://www.darwinsys.com/java/javaResources.jsp#javafx&#034;&gt;this JavaFX section to my Java Resources page&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;img height=&#034;400&#034; width=&#034;600&#034; alt=&#034;JavaFX Effect Playground in action&#034; src=&#034;http://theories.darwinsys.com:80/images/javafx-effect-playground.png&#034; /&gt;
        </description>
      
      
    
    
    
    <category>Open Source Software</category>
    
    <category>OpenBSD</category>
    
    <category>Java</category>
    
    <category>Web</category>
    
    <category>Internet</category>
    
    <comments>http://theories.darwinsys.com:80/2008/12/27/1230396568312.html#comments</comments>
    <guid isPermaLink="true">http://theories.darwinsys.com:80/2008/12/27/1230396568312.html</guid>
    <pubDate>Sat, 27 Dec 2008 16:49:28 GMT</pubDate>
  </item>
  
  <item>
    <title>Django Reverse-Engineer from Existing Legacy Tables</title>
    <link>http://theories.darwinsys.com:80/2008/10/04/1223136720000.html</link>
    
      
        <description>
          I&#039;ve been playing a bit with &lt;a href=&#034;http://www.djangoproject.com/&#034;&gt;Django&lt;/a&gt;, a &lt;a href=&#034;http://www.python.org/&#034;&gt;Python&lt;/a&gt;-based web framework. One thing that people starting in Django seem to miss out on is the standard &amp;quot;how to I make model classes from my existing database tables&amp;quot;? That&#039;s not because you can&#039;t do this, but only because most of the newb tutorials start from the other end. It turns out that you can do this easily using &amp;quot;&lt;a href=&#034;http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb&#034;&gt;manage.py inspectdb&lt;/a&gt;&amp;quot;. And you&#039;re done, at least most of your work is done. This reverse engineering is not as complete as that in &lt;a href=&#034;http://www.seamframework.org/&#034;&gt;Seam&lt;/a&gt; (actually Hibernate) - no compound primary keys, and (presumably because Python&#039;s db support is less general than Java&#039;s JDBC) it only works on a few databases (PostgreSQL, MySQL and SQL Server, IIRC), but for those database it does the bulk of the work for you.&lt;br /&gt;
&lt;br /&gt;
So, this post is a bit away from my usual topics. I admit it, I&#039;m mainly posting this here in hopes that somebody else using a web search will find the answer more quickly.
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <category>Python</category>
    
    <category>Web</category>
    
    <comments>http://theories.darwinsys.com:80/2008/10/04/1223136720000.html#comments</comments>
    <guid isPermaLink="true">http://theories.darwinsys.com:80/2008/10/04/1223136720000.html</guid>
    <pubDate>Sat, 04 Oct 2008 16:12:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>
