<?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>Daniel Eneström &#187; MySQL</title>
	<atom:link href="http://blog.enestrom.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enestrom.com</link>
	<description>Ramblings of a web developer</description>
	<lastBuildDate>Wed, 27 Jan 2010 19:49:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Maintaining state on Tree Component while updating remote data</title>
		<link>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/</link>
		<comments>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:29:01 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Remoting]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=80</guid>
		<description><![CDATA[I suppose I&#8217;m not the only one who&#8217;s had problems with maintaining the state of a flex tree component upon updating the data. Recently I encountered the problem again and decided to crack this nut once and for all. As it turned out it was a lot easier than I had anticipated.
The Scenario
In this particular [...]]]></description>
			<content:encoded><![CDATA[<p>I suppose I&#8217;m not the only one who&#8217;s had problems with maintaining the state of a flex tree component upon updating the data. Recently I encountered the problem again and decided to crack this nut once and for all. As it turned out it was a lot easier than I had anticipated.</p>
<p><strong>The Scenario<br />
</strong>In this particular case I had a tree component displaying a hierarchical view of the pages of a web site. Upon making some certain changes, like dragging and dropping pages to reorder them I felt the need to change the order server-side and reload the data, rather than changing the order inside the dataProvider. I just like it that way better.</p>
<p><strong>The Problem<br />
</strong>So before I reloaded the data I saved the tree&#8217;s open items in a variable called openTreeItems and when I received the new data I tried to reset it by using <em>tree.openItems = openTreeItems</em>.<br />
Nothing happened.</p>
<p><strong>The Research<br />
</strong>So I started doing some research and quickly discovered that to make this work the component uses the <strong>uid</strong> property and on updating the data for the dataProvider Flex reassigns new uid&#8217;s to the items in the collection. So, in short, Flex doesn&#8217;t recognize the items as the same items after the reload, because of the new uid values.</p>
<p>I encountered <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_6.html" target="_blank">this article in the Flex 3 Help pages</a> and started experimenting with creating custom classes that implemented the IUID interface and soon discovered that this was way to complicated for the (actually) quite simple problem I had. The pages in my database had unique ID&#8217;s! Why the h*ll couldn&#8217;t I use these values as the uid values instead of the built-in values?</p>
<p><strong>The Solution</strong><br />
I suddenly had an idea: what if I simply add the uid property to my data serverside by using the id value I already had? This could be done in many ways but I chose to alter my SQL query like so: <em><br />
&#8220;SELECT pages.id, <strong>pages.id uid</strong>, &#8230; FROM pages&#8230;&#8221;</em>. This way the value would be passed on into Flex the same way as all the other values.</p>
<p>And, voilà, it worked!<br />
After this tiny alteration of my SQL query Flex recognized my items as the ones saved in the openTreeItems variable and when using <em>tree.invalidateList()</em> before the update and <em>tree.validateNow()</em> after the update there isn&#8217;t even a flicker upon updating the data. Sweetness!</p>
<p>Hope this helps anyone that has had the same problem.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20090312%2Fmaintaining-state-on-tree-component-while-updating-remote-data%2F&amp;linkname=Maintaining%20state%20on%20Tree%20Component%20while%20updating%20remote%20data"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL Sample Data Creator</title>
		<link>http://blog.enestrom.com/20081023/mysql-sample-data-creator/</link>
		<comments>http://blog.enestrom.com/20081023/mysql-sample-data-creator/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:30:21 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sample data]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=58</guid>
		<description><![CDATA[A year or two back I was in a real need of a lot of sample data for testing a web tool I was working on, so I wrapped up a small tool to generate sample data by defining a few parameters and choosing how many rows to add, using Flex 2 (or perhaps 1.5, [...]]]></description>
			<content:encoded><![CDATA[<p>A year or two back I was in a real need of a lot of sample data for testing a web tool I was working on, so I wrapped up a small tool to generate sample data by defining a few parameters and choosing how many rows to add, using Flex 2 (or perhaps 1.5, don&#8217;t remember). Well today the need arose again, so I went through my old backup files and found it again. I thought I&#8217;d put it up on the web so as maybe someone else could be helped by it. I know it&#8217;s not perfect and only spent a few hours creating it, but if you have any suggestions on how to improve it please write a comment and let me know what you think. I would be glad to update it and eventually make it a really useful tool.</p>
<p><a href="http://mysqlsampledata.enestrom.com" target="_blank">Go to the MySQL Sample Data Creator 1.0</a></p>
<p><a href="http://mysqlsampledata.enestrom.com" target="_blank"><img class="alignnone size-full wp-image-59" title="MySQL Sample Data Creator" src="http://blog.enestrom.com/wp-content/uploads/mysqlsampledatacreator.gif" alt="" width="400" height="294" /></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20081023%2Fmysql-sample-data-creator%2F&amp;linkname=MySQL%20Sample%20Data%20Creator"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20081023/mysql-sample-data-creator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
