<?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>Shaun Abram</title>
	<atom:link href="http://www.shaunabram.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunabram.com</link>
	<description>Java and Technology weblog</description>
	<lastBuildDate>Wed, 13 Jan 2010 19:02:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Selenium talk at SF JUG</title>
		<link>http://www.shaunabram.com/sfjug-selenium/</link>
		<comments>http://www.shaunabram.com/sfjug-selenium/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 07:26:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[JUG]]></category>
		<category><![CDATA[q]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[sfjug]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=749</guid>
		<description><![CDATA[I attended another great San Francisco JUG meeting tonight, this time on How to use Selenium with Maven/Ant to automate testing of web apps.
The talk was given by Chris Bedford, from Build Lackey Labs &#8211; &#8220;Automating the Monkey Work Out and the Quality In!&#8221;. Overall, I thought this was a great talk by Chris. He [...]]]></description>
			<content:encoded><![CDATA[<p>I attended another great <a href="http://www.sfjava.org/calendar/10674274/">San Francisco JUG</a> meeting tonight, this time on <a href="http://www.sfjava.org/calendar/11982857/">How to use Selenium with Maven/Ant to automate testing of web apps</a>.</p>
<p>The talk was given by Chris Bedford, from <a href="http://buildlackey.com/">Build Lackey Labs</a> &#8211; &#8220;Automating the Monkey Work Out and the Quality In!&#8221;. Overall, I thought this was a great talk by Chris. He clearly has a huge amount of experience creating automated tests and integrating them with build tools and he gave a well structured, interesting, well delivered presentation. I have posted a copy of <a href="http://www.shaunabram.com/attachments/testing-java-web-apps-with-selenium5.ppt">Chris&#8217;s slides</a> and I think the video will be posted on the SF JUG site at some point, but I have also posted my notes from the presentation below&#8230;</p>
<h3>Selenium Overview</h3>
<p>Chris started off with an overview of <a href="http://seleniumhq.org/">Selenium</a> &#8211; a tool for automating tests for web based applications. He then introduced us to the Selenium IDE &#8211; a Firefox add-on that allows you to set up tests by recording clicks on a web page, or by manually entering commands. The tests can then be played back as part of your automated test suite.</p>
<h3>Creating Selenium Tests</h3>
<p>Chris showed us the process by both executing an existing test he had already setup, and by walking us through the creation of a new test, which loaded a page, waited for text to be present, clicked on a link, and confirmed that text was present. The test was a html file, but he showed how to export it as <a href="http://testng.org/doc/index.html">TestNG</a> and <a href="http://www.junit.org/">JUnit</a> tests  (although both exports resulted in kind of ugly java code!)</p>
<h3>Possible hiccups with Selenium</h3>
<p>One of the things I thought Chris did well was, in addition to pointing out all the many great things about Selenium, he also pointed out some of the slight issues with Selenium that he has encountered during his time using it, such as</p>
<ul>
<li>Difficulties getting the initial Open page to work</li>
<li>Issues with where the test files get saved</li>
<li>Making sure you have the tests run slow to start with (to avoid timing/loading issues)</li>
<li>The Selenium IDE may be difficult to get working with IE (Firefox is fine)</li>
</ul>
<h3>Selenium Components</h3>
<p>The main Selenium section then finished up with a quick over of the various Selenium Components:</p>
<ul>
<li>Selenium IDE</li>
<li>Selenese Commands</li>
<li>Selenium RC (Remote Control)</li>
</ul>
<p>Chris also had a section on the &#8216;<a href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin</a>&#8216; JavaScript  policy that Selenium manages to circumvent by using the Selenium RC Server. He managed to explain the issue in simple terms.</p>
<h3>Other functional test alternatives</h3>
<p>Chris discussed other functional test alternatives by comparing <a href="http://webtest.canoo.com/webtest/manual/WebTestHome.html">Canoo</a> to Selenium (Canoo is also an automated web app testing framework).</p>
<p>Chris also mentionted <a href="http://code.google.com/p/umangite/">Umangite</a>, Chris Richardson&#8217;s open source testing framework that makes Selenium tests easier to write. I have used this before, and agree it is worth checking out&#8230;</p>
<h3>Using Selenium with Build Tools</h3>
<p>He then discussed using Maven with Selenium, including using <a href="http://cargo.codehaus.org/">Cargo</a> (e.g. using the <a href="http://cargo.codehaus.org/Maven2+plugin">cargo maven2 plugin</a>). Cargo is a set of APIs that assists in</p>
<ul>
<li>installing web containers, such as Tomcat, JBoss</li>
<li>booting and shutting them down</li>
<li>deploying web apps (.wars, .ears)</li>
</ul>
<p>Chris finished the Selenium &#038; build tools section with a quick run through of using Selenium with <a href="http://ant.apache.org/">Ant</a>.</p>
<h4>Continuous Integration</h4>
<p>The final section of the presentation was a talk on Continuous Integration (CI). Chris described CI as: </p>
<ul>
<li>A dedicated box (see my follow up question below!) that runs regular full builds (including tests) of your software</li>
<li>Build triggers when any developer checks into SCM</li>
<li>Team is notified of any issues</li>
</ul>
<p>And talked about how Selenium can be used with <a href="http://hudson-ci.org/">Hudson</a> &#8211; a very cool CI tool from Sun. This leads well into <a href="http://www.sfjava.org/calendar/12296161/">next month&#8217;s SF JUG talk</a>!</p>
<h3>Q&#038;A</h3>
<p>Q: Do you have any info on WebDriver merging with Selenium?<br />
A: No, but sounds interesting!</p>
<p>Q: How closely do test writers work with marketing people?<br />
A: Chris suggested checking out the <a href="http://www.easyb.org/">easyb</a> framework, a behavior driven development framework that allows you to write conditions in a very abstract level, using a DSL that marketers can use and understand. He also suggested looking at the <a href="http://www.fitnesse.org/">fitnesse</a> framework.</p>
<p>Q: I asked Chris via email after the talk what he meant by needing &#8216;dedicated&#8217; box/server for Continuous Integration.<br />
A: He clarified that by &#8216;dedicated&#8217;, he just meant that the build box  should not be a box that you are doing development on, and that there isn&#8217;t anything wrong with having a mix of services on one machine. e.g. having a qa box that has the CI server and maybe hosts the bug tracking system as well&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/sfjug-selenium/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring Enterprise Recipes</title>
		<link>http://www.shaunabram.com/spring-enterprise-recipes/</link>
		<comments>http://www.shaunabram.com/spring-enterprise-recipes/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 18:57:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Products]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=737</guid>
		<description><![CDATA[I recently found out that this book has just been published:
&#8220;Spring Enterprise Recipes: A Problem-Solution Approach&#8221;
It is written by Josh Long and Gary Mak. I have heard Josh speak at several conferences, followed his articles on TheServerSide (as well as on his blog) and recently got to hang out with him at the SoCal Code [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found out that this book has just been published:<br />
&#8220;<a href="http://www.amazon.com/Spring-Enterprise-Recipes-Problem-Solution-Approach/dp/1430224975/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1259951733&#038;sr=8-1">Spring Enterprise Recipes: A Problem-Solution Approach</a>&#8221;<br />
It is written by Josh Long and Gary Mak. I have heard Josh speak at several conferences, followed his articles on TheServerSide (as well as on his <a href="http://www.joshlong.com">blog</a>) and recently got to hang out with him at the SoCal Code Camp. He is very knowledgeable about Spring and enterprise integration and since Gary is already an author of one of the leading Spring books (<a href="http://www.amazon.com/Spring-Recipes-Problem-Solution-Approach-Professionals/dp/1590599799/ref=sr_1_2?ie=UTF8&#038;s=books&#038;qid=1259951733&#038;sr=8-2">Spring recipes</a>), this should be a great book. I have just ordered my copy and will try to post a review when I am done with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/spring-enterprise-recipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;An Introduction to Spring&#8217; at LA Code Camp</title>
		<link>http://www.shaunabram.com/intro-to-spring-lacodecamp/</link>
		<comments>http://www.shaunabram.com/intro-to-spring-lacodecamp/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 01:12:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[codecamp]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=727</guid>
		<description><![CDATA[I gave my &#8216;An Introduction to Spring&#8217; talk today at the LA code camp. It went fairly well I think. I had very little time to go through the Spring MVC module at the end, but perhaps I will give that as a separate talk another day.
I have posted the presentation slides here.
]]></description>
			<content:encoded><![CDATA[<p>I gave my &#8216;An Introduction to Spring&#8217; talk today at the LA code camp. It went fairly well I think. I had very little time to go through the Spring MVC module at the end, but perhaps I will give that as a separate talk another day.</p>
<p>I have posted the presentation slides <a href="http://www.shaunabram.com/attachments/AnIntroToSpring-LACodeCamp2009.ppt">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/intro-to-spring-lacodecamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaking at LA Code Camp</title>
		<link>http://www.shaunabram.com/speaking-at-la-code-camp/</link>
		<comments>http://www.shaunabram.com/speaking-at-la-code-camp/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 04:37:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[codecamp]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=717</guid>
		<description><![CDATA[I am very pleased to say I will be speaking at the LA Code Camp this weekend. My topic is An Introduction to Spring. I will try to post a report from the code camp this weekend&#8230;
This is the same talk I had planned to present at the Silicon Valley Code Camp, so great to [...]]]></description>
			<content:encoded><![CDATA[<p>I am very pleased to say I will be speaking at the <a href="http://www.socalcodecamp.com/">LA Code Camp</a> this weekend. My topic is <a href="http://www.socalcodecamp.com/session.aspx?sid=a3c3ddcf-b78c-489c-9b6d-029cecef1535">An Introduction to Spring</a>. I will try to post a report from the code camp this weekend&#8230;</p>
<p>This is the same talk I had <a href="http://www.shaunabram.com/spring-talk-canceled/">planned</a> to present at the Silicon Valley Code Camp, so great to be finally giving it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/speaking-at-la-code-camp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Project Euler: Problem 4 (in Groovy)</title>
		<link>http://www.shaunabram.com/euler4/</link>
		<comments>http://www.shaunabram.com/euler4/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 09:30:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=630</guid>
		<description><![CDATA[Problem 4 in Project Euler is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.

I found this problem significantly easier than problem 3, thankfully.
My first step was [...]]]></description>
			<content:encoded><![CDATA[<p>Problem 4 in <a href="http://projecteuler.net/">Project Euler</a> is as follows:</p>
<blockquote><p>A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.</p>
<p>Find the largest palindrome made from the product of two 3-digit numbers.
</p></blockquote>
<p>I found this problem significantly easier than problem 3, thankfully.</p>
<p>My first step was to write a helper method:</p>
<pre>
<code>	boolean isPalindrome(int num)</code>
</pre>
<p>My first attempt was, as usual, the brute force approach. Namely, go through every number from 100 to 999 and for each, multiply it by every number between 100 and 999. Check if the result of each of the roughly one million calculations is a palindrome &#8211; and store it if it is the biggest one yet.</p>
<p>My next approach was better and involved starting from the top (999 to 100) instead of the other way round. This means we can check if the largest palindrome we could possible find is smaller than what we have already found, thereby avoiding a large number of useless calculations.</p>
<p>This gave me a solution that runs in approx 500ms on my local PC.</p>
<p>Here is my final solution:</p>
<pre>
<code>int largestPalindrome = 0;
for (i in 999..100) {
	if ( (i*i) &lt; largestPalindrome) {
		//the largest possible number we can now find (i*i)
		//is smaller than the biggest palindrome already found
		break;
	}
	for (j in i..100) {
		int candidate = i*j;
		if ( candidate &lt; largestPalindrome) {
			//largest number we can now find in this inner loop
			//is smaller than the biggest palindrome already found
			break;
		}
		if (isPalindrome(candidate)) {
			if (candidate&gt;largestPalindrome) {
				largestPalindrome = candidate;
				break;//no point checking smaller numbers of j
			}
		}
	}
}
println("largestPalindrome);</code>
</pre>
<p>And finally, my isPalindrome method:</p>
<pre>
<code>public static boolean isPalindrome(Integer num) {
	boolean isPalindrome=true;
	char[] numChars = num.toString().toCharArray();
	int endPoint = numChars.length() - 1;
	int midPoint = numChars.length() / 2;
	for (i in 0..midPoint) {
		char a = numChars[i];
		char b = numChars[endPoint-i];
		if (a != b) {
			isPalindrome=false;
			break;
		}
	}
	return isPalindrome;
}</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/euler4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java User Groups and cultivating your career</title>
		<link>http://www.shaunabram.com/jugs-and-your-career/</link>
		<comments>http://www.shaunabram.com/jugs-and-your-career/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 17:21:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=701</guid>
		<description><![CDATA[There is an interesting article here about the importance of User Groups, which links to this one about cultivating your career.
Both definitely worth a read.
]]></description>
			<content:encoded><![CDATA[<p>There is an interesting article <a href="http://weblogs.java.net/blog/sunahouston/archive/2009/11/09/cultivate-your-career-today-join-user-group">here</a> about the importance of User Groups, which links to <a href="http://blog.polyglotprogramming.com/2009/11/6/cultivateyourcareertoday">this one</a> about cultivating your career.<br />
Both definitely worth a read.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/jugs-and-your-career/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data binding in Spring MVC</title>
		<link>http://www.shaunabram.com/data-binding-in-spring-mvc/</link>
		<comments>http://www.shaunabram.com/data-binding-in-spring-mvc/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:35:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=667</guid>
		<description><![CDATA[Two of the most important tasks carried out by Spring MVC when you submit a form are Data binding and validation.
The following article discusses data binding, including the use of custom PropertyEditors, and some of the options available for registering such editors. Most of the information discussed applies to Spring in general, but its application [...]]]></description>
			<content:encoded><![CDATA[<p>Two of the most important tasks carried out by Spring MVC when you submit a form are Data binding and validation.<br />
The following article discusses data binding, including the use of custom PropertyEditors, and some of the options available for registering such editors. Most of the information discussed applies to Spring in general, but its application in Spring MVC is my primary interest.</p>
<p>In a future article I would like to discuss validation including the use of custom error messages.</p>
<p>Note that these notes relate to version 2.5.6 of Spring, the latest production code at time of writing, and depend heavily on the corresponding <a href="http://static.springsource.org/spring/docs/2.5.x/reference/">Spring reference docs</a>.</p>
<h2>Data Binding</h2>
<p>Spring MVC allows the use of command objects (aka form backing objects, model attributes, domain model objects &#8211; basically the objects used to transport data between your view and your controller) using just about any type. However, the Servlet API deals with form parameters as Strings. Spring uses a technique called data binding to covert between the String representation and the real underlying type. This enables user input to be bound to the objects you use to process user input. In other words, the values entered by a user in a form can be used to set the property values on a chosen object.<br />
As well as binding the values, Spring includes support for validation and binding result analysis. </p>
<p>The binding functionality is provided by Spring&#8217;s <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/validation/DataBinder.html">org.springframework.validation.DataBinder</a> class.<br />
And when converting a String to some arbitrary type, DataBinders make use of ProperEditors. PropertyEditors are not Spring specific, but rather part of the <a href="http://java.sun.com/javase/7/docs/api/java/beans/PropertyEditor.html">JavaBeans API</a>.</p>
<h3>Using PropertyEditors</h3>
<p>Spring heavily uses the concept of PropertyEditors to effect the conversion between an Object and a String.<br />
Spring has a number of built-in PropertyEditors to make life easy (for a complete list, see <a href="http://static.springsource.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion">here</a>).<br />
If you are using a custom type that Spring is unable to convert to and from a String, you will likely receive a lovely error such as this:</p>
<blockquote><p>org.springframework.web.bind.ServletRequestBindingException: Errors binding onto object &#8216;dependsOnExoticType&#8217;; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors<br />
Field error in object &#8216;dependsOnExoticType&#8217; on field &#8216;type&#8217;: rejected value [test]; codes [typeMismatch.dependsOnExoticType.type,typeMismatch.type,typeMismatch.example.ExoticType,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [dependsOnExoticType.type,type]; arguments []; default message [type]]; default message [Failed to convert property value of type [java.lang.String] to required type [example.ExoticType] for property &#8216;type&#8217;; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [example.ExoticType] for property &#8216;type&#8217;: no matching editors or conversion strategy found]</p></blockquote>
<p>The solution is to create your own custom editor.</p>
<h4>Creating a custom property editor</h4>
<p>A custom property editor should be of type java.beans.PropertyEditor. It tells Spring how to convert to a String and back again. As an example, see the ExoticTypeEditor in the Spring reference docs <a href="http://static.springsource.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion-customeditor-registration">here</a>. </p>
<p>The question is then how to register the custom editor. </p>
<h4>Registering your custom editor</h4>
<p>There are several ways to ensure you custom editor gets registered.</p>
<h5>1) Put Editor in same package</h5>
<p>The simplest way (by far!) is to put the Editor in the same package as the class it handles. This is because the standard JavaBeans infrastructure will automatically discover PropertyEditor classes (without you having to register them explicitly) if they are in the same package as the class they handle, and have the same name as that class, with&#8217;Editor&#8217; appended;</p>
<p>However, if putting the Editor in the same package as the class it handlers is not possible (If for example, you are using a custom type from a 3rd party library and hence you don&#8217;t have access to the source code), try one of the other options below&#8230;</p>
<h5>2) CustomEditorConfigurer </h5>
<p>Another approach to registering a custom PropertyEditor is to use a special bean factory post-processor called CustomEditorConfigurer.<br />
This is the approach used in the spring reference manual for the &#8216;ExoticType&#8217; example. Again, see<br />
section 5.4.2.1. Registering additional custom PropertyEditors, <a href="http://static.springsource.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion-customeditor-registration">here</a>.</p>
<p>The CustomEditorConfigurer is used to register the new PropertyEditor with the ApplicationContext, which will then be able to use it as needed.</p>
<h6>Gotchas</h6>
<p><h7>i) Won&#8217;t work with BeanFactory &#8211; only ApplicationContext</h7><br />
The PropertyEditors defined in the &#8216;customEditorConfigurer&#8217; bean will only be automatically used if you are using an ApplicationContext implementation (i.e. will not work for BeanFactory). This is discussed <a href="http://forum.springsource.org/showthread.php?t=15951">here</a>.<br />
<h7>ii) Only works for ApplicationContext created beans &#8211; not data binding beans such as form objects</h7><br />
This approach only works for beans created by the ApplicationContext. The PropertyEditors that are registered via CustomEditorConfigurer are NOT available for use in the data binding infrastructure (this is discussed <a href="http://forum.springsource.org/showthread.php?t=30759">here</a> and <a href="http://jira.springframework.org/browse/SPR-1210">here</a>).<br />
I think this should be made more clear in the spring framework ref docs (although, in fairness, it is covered in the <a href="http://static.springsource.org/spring/docs/3.0.0.M1/javadoc-api/org/springframework/beans/factory/config/CustomEditorConfigurer.html">CustomEditorConfigure javadocs</a>).</p>
<p>
So, if you are using Spring MVC and dealing with form submission, the next option may be better&#8230;</p>
<h5>3) Explicitly register your editor in initBinder</h5>
<p>So, a better approach, as far as form data binding is concerned, is to explicitly register your editor within initBinder() in the relevant Controller. e.g.</p>
<pre>
<code>@Controller
@RequestMapping("/exoticView.htm")
public class TestController {

	//post and get handling methods etc...

	@InitBinder
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
		binder.registerCustomEditor(ExoticType.class, new ExoticTypeEditor());
	}

}</code>
</pre>
<h5>4) Use a WebBindingInitializer</h5>
<p>If you find yourself using the above approach (registering your customer editor in initBinder) in many controllers, and you use a annotation based controller (Spring 2.5+), then you can use a WebBindingInitializer to register global property editors. </p>
<p>To do this, create a class that implements the WebBindingInitializer interface, for example</p>
<pre>
<code>public class GlobalBindingInitializer implements WebBindingInitializer {

    public void initBinder(WebDataBinder binder, WebRequest request) {
        binder.registerCustomEditor(ExoticType.class, new ExoticTypeEditor());
    }

}</code>
</pre>
<p>Then update your web application context file to contain:</p>
<pre>
<code>&lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
    &lt;property name="webBindingInitializer"&gt;
        &lt;bean class="GlobalBindingInitializer"/&gt;
    &lt;/property&gt;
&lt;/bean&gt;</code>
</pre>
<p>I discovered this approach in a posting on <a href="http://stackoverflow.com/about">StackOverflow </a> about <a href="http://stackoverflow.com/questions/1416423/hidden-features-of-spring-framework">hidden features of Spring </a>. It means you can register an editor once and use it anywhere. <strong><em>This is now my preferred way to register custom property editors.</em></strong></p>
<h5>5) Use PropertyEditorRegistrar</h5>
<p>Another mechanism for registering property editors with the Spring container, and the final one in the Spring reference docs, is to create and use a PropertyEditorRegistrar. See section 5.4.2.1.1 <a href="http://static.springsource.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion-customeditor-registration">here</a>. The docs say that this is a good approach &#8220;when you need to use the same set of property editors in several different situations&#8221;. I have used this approach successfully in the past, but to be honest, I don&#8217;t quite see the benefits beyond the GlobalBindingInitializer approach above and it seems to require a few more steps. (I also saw some confusing debate on exactly what steps are mandatory <a href="http://jira.springframework.org/browse/SPR-3512?focusedCommentId=28100&#038;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_28100">here</a>)</p>
<h5>6) BeanInfo</h5>
<p>There is also a BeanInfo mechanism mentioned in the Spring docs which I admit I have never tried &#8211; or fully understood.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/data-binding-in-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HelloWorld: Html -&gt; Servlet -&gt; JSP</title>
		<link>http://www.shaunabram.com/helloworld-html-servlet-jsp/</link>
		<comments>http://www.shaunabram.com/helloworld-html-servlet-jsp/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 09:56:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[el]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=657</guid>
		<description><![CDATA[A couple of times recently I have had to setup up some very simple code to display on the client side (browser) some values created on the server side based on basic user input. 
This has been part of some prototype/proof-of-concept work. I am posting my basic setup as an example in the form of [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of times recently I have had to setup up some very simple code to display on the client side (browser) some values created on the server side based on basic user input. </p>
<p>This has been part of some prototype/proof-of-concept work. I am posting my basic setup as an example in the form of the ubiquitous HelloWorld app. It uses a Html page to receive user input, which is submitted to a Servlet, processed, and the response displayed in a JSP using EL (Expression Language).</p>
<p>Obviously this could be done in various ways, including just JSPs, but this example acts as a template of Html/Servlet/JSP interaction.</p>
<p>1) Create a Html page called HelloWorld.html</p>
<pre>
<code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Greeting Setup - Hello Who?&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;FORM ACTION="/HelloWorld/HelloWorldServlet"&gt;
	Enter greeting recipient:
	&lt;INPUT TYPE="TEXT" NAME="msg"&gt;
	&lt;p&gt;&lt;/p&gt;
	&lt;INPUT TYPE="SUBMIT" VALUE="Submit"&gt;
&lt;/FORM&gt;

&lt;/body&gt;
&lt;/html&gt;</code>
</pre>
<p>2) Create a servlet to receive the user input<br />
HelloWorldServlet.java</p>
<pre>
<code>package com.helloworld;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {

		//get inputs
		String msg = req.getParameter("msg");

		//any additional processing can be done here

		//set outputs
		req.setAttribute("msg", msg);

		//forward to jsp
		req.getRequestDispatcher("/HelloWorld.jsp").forward(req, res);
	} 

}</code>
</pre>
<p>3) Create a JSP to display the response<br />
HelloWorld.jsp:</p>
<pre>
<code>Hello ${msg}</code>
</pre>
<p>4) Create the web application&#8217;s deployment descriptor file:<br />
web.xml</p>
<pre>
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;HelloWorld.html&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;com.helloworld.HelloWorldServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/HelloWorldServlet&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

&lt;/web-app&gt;
</code>
</pre>
<p>That&#8217;s it. </p>
<p>The easiest way I have found for this kind of development is to create in Eclipse as a <a href="http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/twcreprj.html">Dynamic Web Project</a> (available via the <a href="http://www.eclipse.org/webtools/">Web Tools Platform</a> that comes with the in the <a href="http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/galileosr1">&#8220;Eclipse IDE for Java EE Developers&#8221;</a> package). When you have carried out the above steps, just right click the project -> Run As -> Run on Server (assuming you have a server like Tomcat or GlassFish setup in Eclipse&#8230;). </p>
<p>I have <a href="/attachments/HelloWorld.war">attached</a> the source in a war file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/helloworld-html-servlet-jsp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JUG Meetup: Joshua Bloch (Effective Java)</title>
		<link>http://www.shaunabram.com/svwebjug-joshuabloc/</link>
		<comments>http://www.shaunabram.com/svwebjug-joshuabloc/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 06:45:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[JUG]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=652</guid>
		<description><![CDATA[I had the chance tonight to see Joshua Bloch speak at the Silicon Valley Web JUG meetup down at the Googleplex in Mountain View. I have read and blogged about his great book &#8220;Effective Java&#8221; &#8211; probably the single best book I have read on Java &#8211; so it was great to hear him in [...]]]></description>
			<content:encoded><![CDATA[<p>I had the chance tonight to see Joshua Bloch speak at the Silicon Valley Web JUG <a href="http://www.meetup.com/sv-web-jug/calendar/10878461/">meetup</a> down at the Googleplex in Mountain View. I have read and <a href="http://www.shaunabram.com/effective-java/">blogged</a> about his great book &#8220;Effective Java&#8221; &#8211; probably the single best book I have read on Java &#8211; so it was great to hear him in person. The talk covered a couple of examples from his <a href="http://www.amazon.com/gp/product/032133678X">Java Puzzlers</a> book as well as a discussion on some of the items from the Effective Java book. As expected, he was a great presenter, both insightful and funny.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/svwebjug-joshuabloc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaBeans vs Spring beans vs POJOs</title>
		<link>http://www.shaunabram.com/beans-vs-pojos/</link>
		<comments>http://www.shaunabram.com/beans-vs-pojos/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 20:40:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaBeans]]></category>
		<category><![CDATA[POJO]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Sun]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=613</guid>
		<description><![CDATA[The terms JavaBeans, &#8220;Spring beans&#8221; and POJOs are in widespread use and this article discusses each and the differences between them.
JavaBeans
At a basic level, JavaBeans are simply Java classes which adhere to certain coding conventions. For example, classes that

Have a public default (no argument) constructor
allows access to properties using accessor (getter and setter) methods
Implement java.io.Serializable

More [...]]]></description>
			<content:encoded><![CDATA[<p>The terms JavaBeans, &#8220;Spring beans&#8221; and POJOs are in widespread use and this article discusses each and the differences between them.</p>
<h2>JavaBeans</h2>
<p>At a basic level, JavaBeans are simply Java classes which adhere to certain coding conventions. For example, classes that</p>
<ol>
<li>Have a public default (no argument) constructor</li>
<li>allows access to properties using accessor (getter and setter) methods</li>
<li>Implement java.io.Serializable</li>
</ol>
<p>More accurately, JavaBeans are classes that adhere to Sun&#8217;s <a href="http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html">JavaBeans spec</a>, first published way back in 1996. A JavaBean was defined as a &#8220;software component model&#8221; for Java. The idea was that JavaBeans would be reusable software components that could be manipulated visually in a builder tool and that vendors would create and sell JavaBeans that could be composed together into applications by end users. The three most important features of a Java Bean are </p>
<ol>
<li>the set of properties (named attributes) it exposes</li>
<li>the set of methods it allows other components to call</li>
<li>the set of events it fires (to notify registered listeners of changes)</li>
</ol>
<h2>POJO</h2>
<p>POJO is an acronym for Plain Old Java Object. The term was coined by <a href="http://www.martinfowler.com/bliki/POJO.html">Martin Fowler et. al.</a>, as a &#8216;fancy&#8217; way to describe ordinary Java Objects that do not require a framework to use, nor need to be run in a application server environment. If is often used to distinguish simpler, lightweight Java objects from &#8216;heavyweight&#8217; code like EJBs. The use of these kind of lightweight objects in programming is described in books such as &#8220;<a href="http://www.shaunabram.com/18/">POJOs in Action</a>&#8221; and advocated by frameworks like Spring.</p>
<h2>Spring beans</h2>
<p>A Spring bean is basically an object managed by Spring. More specifically, it is an object that is instantiated, configured and otherwise managed by a <a href="http://en.wikipedia.org/wiki/Spring_Framework">Spring Framework</a> container. Spring beans are defined in a Spring configuration file (or, more recently, by using annotations), instantiated by the Spring container, and then injected into your application.</p>
<p>The reason Spring managed objects are referred to as beans is because in the very early versions, Spring was intended only for use with JavaBeans. That is no longer the case of course: Spring can manage just about any object, even if it doesn&#8217;t have JavaBean type characteristics such as default constructors or mutator methods (getters and setters). None the less, the term &#8216;Spring beans&#8217; has stuck. </p>
<p>Can Spring beans be POJOs? Yes, and they usually are (although they don&#8217;t have to be &#8211; e.g. Spring can be used with &#8216;heavyweight&#8217; Java objects, such as EJBs).<br />
Can Spring beans be JavaBeans? As I have said, yes and again they often are but don&#8217;t have to be.</p>
<h2>Summary</h2>
<p>Although it have been well over 10 years since the JavaBeans spec was first published, it still carries weight and has influence the development of modern frameworks such as Spring. But while Java objects that have default constructor and use accessor methods for private fields may legitimately be called JavaBeans, the whole “reusable software component that can be manipulated visually in a builder tool” concept isn’t particularly popular anymore. </p>
<p>POJOs, however, are everywhere and the a backlash against the complexities for EJBs has resulted in widespread use of ‘lightweight’ Java programming.</p>
<p>Spring beans are objects created and managed by the Spring framework.</p>
<p>None of the 3 terms discussed are mutually exclusive. A Java object can be a JavaBean, a POJO and a Spring bean all at the same time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/beans-vs-pojos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
