<?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>Wet Feet - Online Marketing and Technology Blog &#187; Flex</title>
	<atom:link href="http://www.wetfeetblog.com/tag/flex/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wetfeetblog.com</link>
	<description></description>
	<lastBuildDate>Wed, 19 May 2010 15:34:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flex Frameworks &#8211; PuremVC, Mate, Cairngorm and Robotlegs</title>
		<link>http://www.wetfeetblog.com/flex-frameworks-puremvc-mate-cairngorm-robotlegs/297</link>
		<comments>http://www.wetfeetblog.com/flex-frameworks-puremvc-mate-cairngorm-robotlegs/297#comments</comments>
		<pubDate>Wed, 17 Feb 2010 14:00:30 +0000</pubDate>
		<dc:creator>Tomas Mazukna</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[The Journey]]></category>
		<category><![CDATA[Robotlegs]]></category>

		<guid isPermaLink="false">http://www.wetfeetblog.com/?p=297</guid>
		<description><![CDATA[Objective I just wanted to share my thoughts about the frameworks in the Flex environment. You may have noticed that I am in love with Spring when I write Java code, but how about Flex? For a simple example application I go with KISS (keep it stupid simple) approach, but for serious data driven app [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.wetfeetblog.com/wp-content/uploads/2010/02/robotlegssketchsmall.gif" alt="" title="robotlegssketchsmall" width="221" height="260" class="float-right" /><br />
<h3>Objective</h3>
<p>I just wanted to share my thoughts about the frameworks in the Flex environment. You may have noticed that I am in love with Spring when I write Java code, but how about Flex? For a simple example application I go with KISS (keep it stupid simple) approach, but for serious data driven app I utilize a framework.</p>
<h3>How to choose a framework that works for You</h3>
<p>Firs of all you need to know what you are looking for, because if you do not know where you are going, any path will take you there. When I first started to p[lay with Flex about 3 years ago, I noticed that I need to add some structure to the application. Since I was already using Spring I  started looking for a framework. At that point in time there where only two alternatives worth looking at: Cairngorm (heavily pushed by Adobe) and PureMVC.<br />
<span id="more-297"></span><br />
To select a framework I used both framework to build a simple sample application. After spending a day on the exercise I chose PureMVC. PureMVC solution was cleaner, it suited my need better and I felt that it did a better job at structuring the application. I stuck with PureMVC fro quite a while, Until couple month ago I decided to take a look of something better came along.</p>
<p>All the hype was around this English word "Mate", meaning friend or buddy. Even some developers around me have deep religious belief that Mate will save the world. So I had to take a deeper look at this framework. I build a simple application to get a feel for the framework and found that I do not like quite a lot of things about Mate.</p>
<p>First of all everything is done in the sudo code called MXML. I like writing code, I like to have control and make things exactly like they should be and generated code not allays works exactly like I need it to. Then I started looking into some other aspects of the Mate framework and found a better solution. If you are interested in a deeper reading about what I do not like about mate here are couple posts from Shaun that I agree with:</p>
<p><a href="http://shaun.boyblack.co.za/blog/2009/03/13/as3-dependency-injection-and-autowire/">AS3 Dependency Injection and [Autowire]</a><br />
<a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/">Another Architectural Framework, But Why?</a></p>
<p>After looking around I chose to use <a href="http://www.robotlegs.org/">Robotlegs Framework</a>. It gave me exactly what I needed: dependency injection, mediators and proxies.  What you need for your application may be completely different and you may choose another framework, but give robotlegs a good look over to see if it will fit your need too.</p>
<h3>Conclusion</h3>
<p>Select a framework with a particular need in mind, don&#8217;t just use one because Adobe pushed it or your mate recommended it. Understand framewrok&#8217;s pros and cons and choose the one that give you the most bang per line of code or xml if that is your coding flavor.</p>
<p>Let me know in the comments which other framework you have used and would recommend to others.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wetfeetblog.com/flex-frameworks-puremvc-mate-cairngorm-robotlegs/297/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goolge app engine + java + spring + REST + JSON + Flex – Part 2</title>
		<link>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-2/147</link>
		<comments>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-2/147#comments</comments>
		<pubDate>Thu, 29 Oct 2009 12:42:27 +0000</pubDate>
		<dc:creator>Tomas Mazukna</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.wetfeetblog.com/?p=147</guid>
		<description><![CDATA[Objective Once you are finished with this article, you will be able to store application data in Google App Engine Data store and consume REST service using flex client. Common Problems and Solutions In my personal opinion flash player security model is the biggest piece of bullshit I ever encountered. If you sit down and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.wetfeetblog.com/wp-content/uploads/2009/10/www_1.jpg" alt="www_1" title="www_1" class="float-right" /></p>
<h3>Objective</h3>
<p>Once you are finished with this article, you will be able to store application data in Google App Engine Data store and consume REST service using flex client.</p>
<h3>Common Problems and Solutions</h3>
<p>In my personal opinion flash player security model is the biggest piece of bullshit I ever encountered. If you sit down and thing just for 10 seconds about how it is implemented you will have to agree that it provides NO security at all. It just makes impossible so do certain things, that&#8217;s all. Adobe needs to drop it now.</p>
<p>Here is the problem that we have with REST and Google app engine: Adobe&#8217;s implementation of HTTPService only supports GET and POST, to consume REST we need at least 3 methods: GET, POST and DELETE. We can live without PUT &#8211; if id is null JDO will create a new persisted object, if it is set JDO will update it. But we still do not have support for DELETE. <span id="more-147"></span></p>
<p>If you are implementing Air Application there are good news: <a href="http://code.google.com/p/as3httpclientlib/">as3httpclientlib</a> &#8211; a socket implementation of http client that can do all that we need: HEAD, GET, POST, PUT, DELETE. It depends on <a href="http://code.google.com/p/as3corelib/">as3corelib</a> and <a href="http://code.google.com/p/as3crypto/">as3crypto</a>, so grab those too.</p>
<p>If you are implementing a web application in google app engine, you are out of luck with as3httpclientlib. The reason is that adobe has this perverted understanding about security: since as3httpclientlib utilizes the Socket to implement http client adobe flash player tries to &#8220;protect&#8221; the server that socket is trying to connect by sending<br />
&#8220;&#060;policy-file-request/&#062;&#8221; to the 843 port to get a scoket policy file, it that fails it tries the port the socket is trying to connect to. Since this is not a http request, google app engine ignores it, and you can not create sockets in google app engine &#8211; they are not supported, so you can not write a simple class to send back what flash player wants. The conclusion: Adobe Flex has not yet made it to Web 2.0, it can not talk REST to the server. But there are workarounds and here is mine:</p>
<h3>Step one &#8211; Add persistence management code to the project we created in <a href="http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-1/87">part 1</a></h3>
<p>First we need to modify our <strong>User.java</strong> class to support persistence:</p>
<pre>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">import</span> <span class="co2">javax.jdo.annotations.IdGeneratorStrategy</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.annotations.IdentityType</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.annotations.PersistenceCapable</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.annotations.Persistent</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.annotations.PrimaryKey</span><span class="sy0">;</span>

@PersistenceCapable<span class="br0">&#40;</span>identityType <span class="sy0">=</span> IdentityType.<span class="me1">APPLICATION</span>, detachable<span class="sy0">=</span><span class="st0">&quot;true&quot;</span><span class="br0">&#41;</span>
<span class="kw1">public</span> <span class="kw1">class</span> User <span class="br0">&#123;</span>

&nbsp; &nbsp; @PrimaryKey
&nbsp; &nbsp; @Persistent<span class="br0">&#40;</span>valueStrategy <span class="sy0">=</span> IdGeneratorStrategy.<span class="me1">IDENTITY</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="kw1">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Along+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Long</span></a> id<span class="sy0">;</span>
&nbsp; &nbsp; @Persistent
&nbsp; &nbsp; <span class="kw1">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> email<span class="sy0">;</span>
&nbsp; &nbsp; @Persistent
&nbsp; &nbsp; <span class="kw1">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> name<span class="sy0">;</span>

&nbsp; &nbsp; <span class="co1">// Getter and setters go here......</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>As you can see we have instructed JDO that we will store User objects at application level, added a primary key and its generation strategy and annotated members to be persisted.</p>
<p>Next we need to get hold of a persistence manager factory, since it is a very very costly operation, we wan to do it only once in the lifetime of our application. For this purpose lets create a singleton which will hold this instance for us:</p>
<pre>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">package</span> <span class="co2">com.lureto.rjf</span><span class="sy0">;</span>

<span class="kw1">import</span> <span class="co2">javax.jdo.JDOHelper</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.PersistenceManager</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.PersistenceManagerFactory</span><span class="sy0">;</span>

<span class="kw1">public</span> <span class="kw1">class</span> PMF <span class="br0">&#123;</span>

&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">final</span> PersistenceManagerFactory pmfInstance <span class="sy0">=</span> 
JDOHelper.<span class="me1">getPersistenceManagerFactory</span><span class="br0">&#40;</span><span class="st0">&quot;transactions-optional&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>

&nbsp; &nbsp; <span class="kw1">private</span> PMF<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span>

&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> PersistenceManager getManager<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> pmfInstance.<span class="me1">getPersistenceManager</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> PersistenceManagerFactory get<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> pmfInstance<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>

<span class="br0">&#125;</span></div>
</div>
</pre>
<p>The last step is to modify our <strong>UserContrller.java</strong> to actually store and retrieve the User objects from the data store.</p>
<pre>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">package</span> <span class="co2">com.lureto.rjf</span><span class="sy0">;</span>

<span class="kw1">import</span> <span class="co2">java.io.IOException</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">java.util.List</span><span class="sy0">;</span>

<span class="kw1">import</span> <span class="co2">javax.jdo.PersistenceManager</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">javax.jdo.Query</span><span class="sy0">;</span>

<span class="kw1">import</span> <span class="co2">org.apache.log4j.Logger</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.stereotype.Controller</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.web.bind.annotation.ModelAttribute</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.web.bind.annotation.PathVariable</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.web.bind.annotation.RequestBody</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.web.bind.annotation.RequestMapping</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.springframework.web.bind.annotation.RequestMethod</span><span class="sy0">;</span>

@Controller
@RequestMapping<span class="br0">&#40;</span><span class="st0">&quot;/user&quot;</span><span class="br0">&#41;</span>
<span class="kw1">public</span> <span class="kw1">class</span> UserController <span class="br0">&#123;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">static</span> Logger logger <span class="sy0">=</span> Logger.<span class="me1">getLogger</span><span class="br0">&#40;</span> UserController.<span class="kw1">class</span> <span class="br0">&#41;</span><span class="sy0">;</span>

&nbsp; &nbsp; &nbsp; &nbsp; @SuppressWarnings<span class="br0">&#40;</span><span class="st0">&quot;unchecked&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; @ModelAttribute<span class="br0">&#40;</span><span class="st0">&quot;users&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; @RequestMapping<span class="br0">&#40;</span>value <span class="sy0">=</span> <span class="st0">&quot;/&quot;</span>, method <span class="sy0">=</span> RequestMethod.<span class="me1">GET</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">List</span></a> listUsers<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">IOException</span></a> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PersistenceManager pm <span class="sy0">=</span> PMF.<span class="me1">getManager</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span class="sy0">=</span> pm.<span class="me1">newQuery</span><span class="br0">&#40;</span>User.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">List</span></a> users<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; users <span class="sy0">=</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">List</span></a><span class="br0">&#41;</span> query.<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query.<span class="me1">closeAll</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> users<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; @ModelAttribute<span class="br0">&#40;</span><span class="st0">&quot;user&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; @RequestMapping<span class="br0">&#40;</span>value <span class="sy0">=</span> <span class="st0">&quot;/&quot;</span>, method <span class="sy0">=</span> RequestMethod.<span class="me1">POST</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> User saveUser<span class="br0">&#40;</span> @RequestBody User user <span class="br0">&#41;</span> <span class="kw1">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">IOException</span></a> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span>user<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PersistenceManager pm <span class="sy0">=</span> PMF.<span class="me1">getManager</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pm.<span class="me1">makePersistent</span><span class="br0">&#40;</span>user<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pm.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> user<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; @RequestMapping<span class="br0">&#40;</span>value <span class="sy0">=</span> <span class="st0">&quot;/{userId}&quot;</span>, method <span class="sy0">=</span> RequestMethod.<span class="me1">DELETE</span> <span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> deleteUser<span class="br0">&#40;</span> @PathVariable <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> userId <span class="br0">&#41;</span> <span class="kw1">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">IOException</span></a> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deleteUserIntenral<span class="br0">&#40;</span>userId<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; @RequestMapping<span class="br0">&#40;</span>value <span class="sy0">=</span> <span class="st0">&quot;/{userId}/delete&quot;</span>, method <span class="sy0">=</span> RequestMethod.<span class="me1">POST</span> <span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> deleteUser2<span class="br0">&#40;</span> @PathVariable <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> userId <span class="br0">&#41;</span> <span class="kw1">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">IOException</span></a> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deleteUserIntenral<span class="br0">&#40;</span>userId<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">private</span> <span class="kw4">void</span> deleteUserIntenral<span class="br0">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> userId <span class="br0">&#41;</span> <span class="kw1">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">IOException</span></a> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;Deleting user id &gt; &quot;</span><span class="sy0">+</span>userId<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; PersistenceManager pm <span class="sy0">=</span> PMF.<span class="me1">getManager</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Along+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Long</span></a> id <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Along+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Long</span></a>.<span class="me1">parseLong</span><span class="br0">&#40;</span>userId<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User user <span class="sy0">=</span> pm.<span class="me1">getObjectById</span><span class="br0">&#40;</span> User.<span class="kw1">class</span>, id <span class="br0">&#41;</span><span class="sy0">;</span> 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pm.<span class="me1">deletePersistent</span><span class="br0">&#40;</span>user<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pm.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>As you can see from the code above, saving and getting a list of Users is pretty trivial coding task. You may also notice that we added <strong>deleteUser(@PathVariable String userId)</strong> method to delete the user when a delete request is made with user id added to the end of the path. To delete the user object first we need to fetch it from the data store and only then ask persistence manager to delete it. We hav two ways to delte the user &#8211; sending DELETE requests and sending POST to &#8220;/api/user/{userId}/delete&#8221;. The post method is there to get around the shortcomings of Actions Scrip 3.</p>
<p>And one last change we need to make to support not so mature flex &#8211; to add <strong>crossdomain.xml</strong> file to /war of our project so flash player security implementation  stops throwing security exceptions. Like I said before this adds nothing to the security, but annoys the hell out of the developers. Here is the contents:</p>
<pre>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span><span class="re2">?&gt;</span></span><span class="sc0">&lt;!DOCTYPE cross-domain-policySYSTEM </span>
<span class="sc0"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;&gt;</span>
<span class="sc3"><span class="re1">&lt;cross-domain-policy<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;allow-access-from</span> <span class="re0">domain</span>=<span class="st0">&quot;*&quot;</span> <span class="re0">to-ports</span>=<span class="st0">&quot;*&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;allow-http-request-headers-from</span> <span class="re0">domain</span>=<span class="st0">&quot;*&quot;</span> <span class="re0">headers</span>=<span class="st0">&quot;*&quot;</span><span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/cross-domain-policy<span class="re2">&gt;</span></span></span></div>
</div>
</pre>
<h3>Step two- Create Flex project to consume the service we just upgraded</h3>
<p>First create a Flex Web application project:<br />
<img class="alignnone size-full wp-image-157" title="project_step_1" src="http://www.wetfeetblog.com/wp-content/uploads/2009/10/project_step_11.png" alt="project_step_1" width="404" height="460" /></p>
<p>and then layout the UI to look like this:<br />
<img class="alignnone size-full wp-image-160" title="project_step_2" src="http://www.wetfeetblog.com/wp-content/uploads/2009/10/project_step_21.png" alt="project_step_2" width="589" height="365" /></p>
<p>And if you lazy like and want it all right now, here is the complete sudo code mxml file:</p>
<pre>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span>
<span class="sc3"><span class="re1">&lt;mx:Application</span> <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span class="sc3"> &nbsp; &nbsp; &nbsp;<span class="re0">layout</span>=<span class="st0">&quot;absolute&quot;</span> <span class="re0">creationComplete</span>=<span class="st0">&quot;init()&quot;</span><span class="re2">&gt;</span></span>
&nbsp; 
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Script<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; <span class="sc2">&lt;![CDATA[</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.rpc.events.ResultEvent;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.rpc.events.FaultEvent;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.rpc.http.HTTPService;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.managers.PopUpManager;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import json.JParser;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.controls.Alert;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;import mx.controls.List;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;[Bindable]</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;private var users:Array;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;private var uriBase: String = &quot;http://localhost:8080/api/user/&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;private var popupLabel:Label;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;private function init() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var myUrl : String = Application.application.url;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;if( myUrl.indexOf( &quot;file://&quot; ) != 0 ) </span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uriBase = myUrl.substring( 0, myUrl.lastIndexOf( &quot;/&quot; ) ) + &quot;/api/user/&quot; ;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;refreshUsers() &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;private function addNew() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_id.text = &quot;&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_email.text = &quot;&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_name.text = &quot;&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;private function updateEdit() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_id.text = &nbsp;this.usersList.selectedItem.id;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_name.text = &nbsp;this.usersList.selectedItem.name;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.user_email.text = &nbsp;this.usersList.selectedItem.email;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;private function deleteUser() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;if( usersList.selectedItem == null )</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;showPopupWait();</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var service: HTTPService = new HTTPService();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.contentType = &quot;application/json&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.method = &quot;POST&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.resultFormat = &quot;text&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.url = uriBase + usersList.selectedItem.id + &quot;/delete&quot; ;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.useProxy = false;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( FaultEvent.FAULT , function(event:FaultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;removePopup();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alert.show( event.message.toString() );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( ResultEvent.RESULT , function(event:ResultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;refreshUsers(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.send();</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;private function saveUser() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;showPopupWait();</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var service: HTTPService = new HTTPService();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.contentType = &quot;application/json&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.method = &quot;POST&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.resultFormat = &quot;text&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.url = uriBase;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.useProxy = false;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( FaultEvent.FAULT , function(event:FaultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;removePopup();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alert.show( event.message.toString() );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( ResultEvent.RESULT , function(event:ResultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var response: Object = JParser.decode( event.message.body.toString() );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user_id.text = response.user.id;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;refreshUsers(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>


<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var user:Object = new Object();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;if( this.user_id.text.length &gt; 0 )</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user.id = this.user_id.text</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;user.name = this.user_name.text;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;user.email = this.user_email.text;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var json:String = JParser.encode( user );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var jsonData:ByteArray = new ByteArray();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;jsonData.writeUTFBytes(json);</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;jsonData.position = 0;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var contentType:String = &quot;application/json&quot;;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;//client.post(uri, jsonData, contentType);</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.send( jsonData );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;private function refreshUsers() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;showPopupWait();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;var service: HTTPService = new HTTPService();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.contentType = &quot;application/json&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.method = &quot;GET&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.resultFormat = &quot;text&quot;;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;// add random number to make browser grab new list.... sux, but works.</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.url = uriBase+&quot;?&quot;+ (new Date).getTime();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.useProxy = false;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( FaultEvent.FAULT , function(event:FaultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;removePopup();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alert.show( event.message.toString() );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.addEventListener( ResultEvent.RESULT , function(event:ResultEvent):void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var userList: Object = JParser.decode( event.message.body.toString() );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;users = userList.users as Array ;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;removePopup();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} ) &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;service.send(); &nbsp; &nbsp; &nbsp; &nbsp;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>

<span class="sc2"> &nbsp; &nbsp; &nbsp;public function showPopup( message:String ) : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;if( this.popupLabel == null ) {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.popupLabel = new Label();</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.popupLabel.text = &nbsp;message ;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.popupLabel.setStyle( &quot;fontSize&quot; , &quot;22&quot; );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.popupLabel.setStyle( &quot;fontWeight&quot; , &quot;bold&quot; );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PopUpManager.addPopUp( this.popupLabel, this, true );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PopUpManager.centerPopUp( this.popupLabel );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;}</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;public function showPopupWait() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.showPopup( &quot;Please wait.....&quot;);</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;public function removePopup() : void {</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;if( this.popupLabel != null )</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PopUpManager.removePopUp( this.popupLabel );</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;this.popupLabel = null;</span>
<span class="sc2"> &nbsp; &nbsp; &nbsp;}</span>

<span class="sc2"> &nbsp; &nbsp;]]&gt;</span>
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:Script<span class="re2">&gt;</span></span></span>
&nbsp; 
&nbsp; <span class="sc3"><span class="re1">&lt;mx:DataGrid</span> <span class="re0">x</span>=<span class="st0">&quot;10&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;35&quot;</span> <span class="re0">id</span>=<span class="st0">&quot;usersList&quot;</span> <span class="re0">dataProvider</span>=<span class="st0">&quot;{users}&quot;</span> </span>
<span class="sc3"> &nbsp; &nbsp; &nbsp; <span class="re0">width</span>=<span class="st0">&quot;469&quot;</span> <span class="re0">height</span>=<span class="st0">&quot;159&quot;</span> <span class="re0">itemClick</span>=<span class="st0">&quot;updateEdit()&quot;</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:columns<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:DataGridColumn</span> <span class="re0">headerText</span>=<span class="st0">&quot;ID&quot;</span> <span class="re0">dataField</span>=<span class="st0">&quot;id&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:DataGridColumn</span> <span class="re0">headerText</span>=<span class="st0">&quot;Email&quot;</span> <span class="re0">dataField</span>=<span class="st0">&quot;email&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:DataGridColumn</span> <span class="re0">headerText</span>=<span class="st0">&quot;Name&quot;</span> <span class="re0">dataField</span>=<span class="st0">&quot;name&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:columns<span class="re2">&gt;</span></span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:DataGrid<span class="re2">&gt;</span></span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Label</span> <span class="re0">x</span>=<span class="st0">&quot;10&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;10&quot;</span> <span class="re0">text</span>=<span class="st0">&quot;Users&quot;</span> <span class="re0">fontSize</span>=<span class="st0">&quot;14&quot;</span> <span class="re0">fontWeight</span>=<span class="st0">&quot;bold&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">x</span>=<span class="st0">&quot;487&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;59&quot;</span> <span class="re0">label</span>=<span class="st0">&quot;Add New&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;addNew()&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">x</span>=<span class="st0">&quot;487&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;89&quot;</span> <span class="re0">label</span>=<span class="st0">&quot;Delete&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;76&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;deleteUser()&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">x</span>=<span class="st0">&quot;487&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;119&quot;</span> <span class="re0">label</span>=<span class="st0">&quot;Refresh&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;76&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;refreshUsers()&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Form</span> <span class="re0">x</span>=<span class="st0">&quot;10&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;202&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;469&quot;</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:FormItem</span> <span class="re0">label</span>=<span class="st0">&quot;User ID&quot;</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;user_id&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;353&quot;</span> <span class="re0">editable</span>=<span class="st0">&quot;false&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:FormItem<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:FormItem</span> <span class="re0">label</span>=<span class="st0">&quot;User Name&quot;</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;user_name&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;353&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:FormItem<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:FormItem</span> <span class="re0">label</span>=<span class="st0">&quot;User Email&quot;</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;user_email&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;353&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:FormItem<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:FormItem<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">label</span>=<span class="st0">&quot;Save&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;96&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;saveUser()&quot;</span><span class="re2">/&gt;</span></span>
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:FormItem<span class="re2">&gt;</span></span></span>
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:Form<span class="re2">&gt;</span></span></span>
&nbsp; 
<span class="sc3"><span class="re1">&lt;/mx:Application<span class="re2">&gt;</span></span></span></div>
</div>
</pre>
<p>To serialize objects to and from the server we need a JSON library. I chose <a href="http://www.waynemike.pwp.blueyonder.co.uk/jswoof/">JSwoof.swc</a> &#8211; JSON serializer and parser. I found it to be a little better qauality then the one in as3corelib, but you can use either one.</p>
<p>Once you get the project compiling, start your google app engine project locally, mine is configured to listen on port 8080, and then you can run the flex project. For the lazy (like me) here is the <a href="http://www.wetfeetblog.com/wp-content/uploads/2009/10/json-rest-client.zip">full project</a> all ready to go.</p>
<h3>Conclusion</h3>
<p>Adding persistence support in google app engine project is not hard, you just need to read documentation carefully.</p>
<p>The harder part is to get flex talking to these services. Like any closed source solution you are at mercy of company making it, like we see in this particular case. Unfortunately there are no better alternative to FLex for building nice looking af functional web application, we just need to deal with its shortcomings.</p>
<p>You can check out the working application at <a href="http://rest-json-flex.appspot.com/">rest-json-flex.appspot.com</a></p>
<p>In <a href="http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-3/185">step 3 we will add session management</a>, user authentication and authorization to our google app engine REST application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-2/147/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Goolge app engine + java + spring + REST + JSON</title>
		<link>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json/85</link>
		<comments>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json/85#comments</comments>
		<pubDate>Wed, 07 Oct 2009 12:20:50 +0000</pubDate>
		<dc:creator>Tomas Mazukna</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.wetfeetblog.com/?p=85</guid>
		<description><![CDATA[I have been inching to try out google app engine and its capabilities, but did not wan to give up the spring. So to day I am starting on my prototype involving Goolge app engine + java + spring + REST + JSON. The end product will be spring mvc app running in google app [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.wetfeetblog.com/wp-content/uploads/2009/10/binary_code_3.jpg" alt="binary_code_3" title="binary_code_3" class="float-right" /></p>
<p>I have been inching to try out google app engine and its capabilities, but did not wan to give up the spring. So to day I am starting on my prototype involving Goolge app engine + java + spring + REST + JSON.</p>
<p>The end product will be spring mvc app running in google app engine handling GET, POST, PUT and DELETE http requests with JSON objects in and out utilizing JDO and seesions. This will give me a platform to write clients in Objective C for Ipod/Iphone (aka Coco Touch), Android, Flex, Ajax and maybe couple more platforms.</p>
<p>I am writing this while I am downloading Spring 3.0RC1. Will try to give daily updates if I can. If my prototype works as expected (all the research points to yes), I will have sample project available for download. There will be some trouble getting Flex to talk REST, since it only supports GET and POST and like most Adobe development stuff is not of the greatest maturity&#8230;&#8230;. (opening new tab to check if we have new version of flex&#8230; still beta). Anyhow, Flex REST part will be interesting, I have already done some hacking in that area and it can be done &#8211; I have to write http client by hand, but who does not like an interesting challenge?</p>
<p>So here you have it. Next update when I have Spring 3 mvc inside google app engine up and running.</p>
<p><a href="http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-1">The part 1 is now online.</a></p>
<p><a href="http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-2/147">The part 2 is now online.</a></p>
<p><a href="http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json-flex-part-3/185">The part 3 is now online</a></p>
<p><a href="http://www.wetfeetblog.com/google-app-engine-java-spring-rest-mapping-exceptions-to-errors-for-json/212">The part 4 is now online</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wetfeetblog.com/goolge-app-engine-java-spring-rest-json/85/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
