<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>handy &#187; multi-select</title>
	<atom:link href="http://sirinsevinc.wordpress.com/tag/multi-select/feed/" rel="self" type="application/rss+xml" />
	<link>http://sirinsevinc.wordpress.com</link>
	<description>java,webservice,javascript,software algorithms</description>
	<lastBuildDate>Mon, 20 Jul 2009 14:24:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sirinsevinc.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/22dbbb1103eab00233fa34b9029d78b4?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>handy &#187; multi-select</title>
		<link>http://sirinsevinc.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sirinsevinc.wordpress.com/osd.xml" title="handy" />
		<item>
		<title>CustomEditor for binding in Spring-MVC</title>
		<link>http://sirinsevinc.wordpress.com/2008/07/02/customeditor-for-binding-in-spring-mvc/</link>
		<comments>http://sirinsevinc.wordpress.com/2008/07/02/customeditor-for-binding-in-spring-mvc/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 14:52:56 +0000</pubDate>
		<dc:creator>sirin sevinc</dc:creator>
				<category><![CDATA[spring-mvc]]></category>
		<category><![CDATA[binding error]]></category>
		<category><![CDATA[CustomCollectionEditor]]></category>
		<category><![CDATA[multi-select]]></category>

		<guid isPermaLink="false">http://sirinsevinc.wordpress.com/?p=26</guid>
		<description><![CDATA[In Spring MVC If you want to create a page with multi-select box , here are some tricks.
suppose that you have a command object defined like this :
public class FooCommand {
private Set&#60;Foo&#62; foos
//setter-getter
}
//Foo class
public class Foo {
private String id;
private String name;
//setter-getter
}

and you want to display a set of foo objects in a multi-select box.
your jsp [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sirinsevinc.wordpress.com&blog=2562058&post=26&subd=sirinsevinc&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In Spring MVC If you want to create a page with multi-select box , here are some tricks.<br />
suppose that you have a command object defined like this :</p>
<div style="background-color:rgb(245, 245, 245);"><code style="font-size:9pt;">public class FooCommand {<br />
private Set&lt;Foo&gt; foos<br />
//setter-getter<br />
}<br />
//Foo class<br />
public class Foo {<br />
private String id;<br />
private String name;<br />
//setter-getter<br />
}<br />
</code></div>
<p>and you want to display a set of foo objects in a multi-select box.<br />
your jsp page should look like this :</p>
<div style="background-color:rgb(245, 245, 245);"><code style="font-size:8pt;">&lt;form:form commandName="fooCommand"&gt;<br />
&lt;div&gt;&lt;label for="tags"&gt;&lt;spring:message code="layoutelementcontent.tags" /&gt;  &lt;/label&gt;<br />
&lt;form:select  path="foos" multiple="true"&gt;<br />
&lt;form:option value=""&gt;Select Here ---&gt;&lt;/form:option&gt;<br />
&lt;c:forEach varStatus="loop" items="${fooList}" var="foo"&gt;<br />
&lt;form:option value="${foo.id}" label="${foo.name}"&gt;&lt;/form:option&gt;<br />
&lt;/c:forEach&gt;<br />
&lt;/form:select&gt;<br />
&lt;/div&gt;<br />
&lt;input type="submit" value="submit" alt="Submit"/&gt;<br />
&lt;/form:form&gt;<br />
</code></div>
<p>Most probably you won&#8217;t have any problem displaying the page. However things get nasty when you try to submit the page. Here is the binding error returned<br />
&#8220;<strong>Failed to convert property value of type [java.lang.String[]] to required type [java.util.Set]</strong> &#8220;<br />
In order to solve this problem you have to use CustomCollectionEditor and you need to register this editor just before binding operation starts.<br />
So in your controller you should have some code like this :</p>
<div style="background-color:rgb(245, 245, 245);"><code style="font-size:9pt;">@Override<br />
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {<br />
//do whatever<br />
/* "foos" is the name of the property that we want to register a custom editor to<br />
* you can set property name null and it means you want to register this editor for occurrences of Set class in * command object<br />
*/<br />
binder.registerCustomEditor(Set.class, "foos", new CustomCollectionEditor(Set.class) {<br />
@Override<br />
protected Object convertElement(Object element) {<br />
String fooId = (String) element;<br />
Foo foo = new Foo();<br />
foo.setId(fooId);<br />
return foo;<br />
}<br />
});<br />
}<br />
</code></div>
<p>So basically what we have done above is we force binder to use our custom editor  when the property &#8220;foos&#8221; is binded from request to our FooCommand object.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sirinsevinc.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sirinsevinc.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sirinsevinc.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sirinsevinc.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sirinsevinc.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sirinsevinc.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sirinsevinc.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sirinsevinc.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sirinsevinc.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sirinsevinc.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sirinsevinc.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sirinsevinc.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sirinsevinc.wordpress.com&blog=2562058&post=26&subd=sirinsevinc&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sirinsevinc.wordpress.com/2008/07/02/customeditor-for-binding-in-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a9d9718257bc3dedcd892134e22b4295?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirinse</media:title>
		</media:content>
	</item>
	</channel>
</rss>