<?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>getRIAed &#187; multiple fields</title>
	<atom:link href="http://ravimarella.com/getriaed/tag/multiple-fields/feed/" rel="self" type="application/rss+xml" />
	<link>http://ravimarella.com/getriaed</link>
	<description>flex,flash,AIR</description>
	<lastBuildDate>Wed, 28 Jul 2010 19:34:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Searching Flex XMLListCollection using IViewCursor</title>
		<link>http://ravimarella.com/getriaed/2009/07/01/searching-flex-xmllistcollection-using-iviewcursor/</link>
		<comments>http://ravimarella.com/getriaed/2009/07/01/searching-flex-xmllistcollection-using-iviewcursor/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 09:01:40 +0000</pubDate>
		<dc:creator>ravi</dc:creator>
				<category><![CDATA[IViewCursor]]></category>
		<category><![CDATA[XMLListCollection]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[finAny()]]></category>
		<category><![CDATA[multiple fields]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://ravimarella.com/getriaed/?p=79</guid>
		<description><![CDATA[This post explains how to search a XmlListColelction for multiple fields using IViewCursor&#8217;s findAny() method . Recently in one of my projects, I&#8217;d to use the IViewCursor to search the XMLListCollection and faced some problems initially but implemented it successfully after doing some research. I&#8217;m posting the same example (-) the actual database contents&#8230;i&#8217;ll use [...]]]></description>
			<content:encoded><![CDATA[<p>This post explains how to search a XmlListColelction for multiple fields using IViewCursor&#8217;s findAny() method .</p>
<p>Recently in one of my projects, I&#8217;d to use the IViewCursor to search the XMLListCollection and faced some problems initially but implemented it successfully after doing some research. I&#8217;m posting the same example (-) the actual database contents&#8230;i&#8217;ll use sample XML files for the purpose of this example.</p>
<p>The scenario for which i&#8217;ve implemented this thing is as follows:<span id="more-79"></span></p>
<p>I&#8217;ve three tables users,courses and privileges. The users and courses tables contains the details of the existing courses and users and the privileges table contains the course&#8211;&gt;user mappings and access levels.</p>
<p>Now in flex, i&#8217;m using datagrid to show the privileges&#8230;and another form to create new priviliges. This form contains<br />
two list boxes for users and courses and checkboxes for each privilege.</p>
<p>So when the admin of my application selects a course and user and if that user has already has some privileges over that course, those privileges have to be shown by autoselcting the corresponding checkboxes.</p>
<p>So to match the selected user and course with the existing privileges, i&#8217;m using IViewCursor. but the IviewCursor&#8217;s findAny() method returns true if either course or user is found in the privileges list which is not exactly what i&#8217;m expecting&#8230;i.e return true only if a row contains both the selected user and course.</p>
<p>And here is the sample of the application:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_XMLListCollectionSearch_1246301426"
			class="flashmovie"
			width="620"
			height="450">
	<param name="movie" value="http://ravimarella.com/getriaed/wp-content/uploads/2009/07/XMLListCollectionSearch.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://ravimarella.com/getriaed/wp-content/uploads/2009/07/XMLListCollectionSearch.swf"
			name="fm_XMLListCollectionSearch_1246301426"
			width="620"
			height="450">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Right Click/Click on the view source button to view the source of this application.</p>
<p>Now some explanation:</p>
<p>The application contains a datagrid which shows the privileges of a particular user on a particular course and two list boxes showing all the available courses and users. When you select a user and a course, an Alert box appears if the selected user has some priviliges allocated to her on the selected course.</p>
<p>To do this, first of all i&#8217;ve stored my data in 3 XML files</p>
<ul>
<li>Privileges.xml contains the details of which user has what priviges on a course</li>
<li>Course.xml contains details of  courses available</li>
<li>users.xml contains details of all users available</li>
</ul>
<p>There is an XMLListCollection named privilegesModel in to which the privileges.xml is loaded. Once it is loaded, i&#8217;ve sorted the collection on the two criteria on which i&#8217;m going to search i.e user name and the course name like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">privilegesCollection.<span style="color: #004993;">source</span>=e.result.row;<br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> sortValue<span style="color: #000000; font-weight: bold;">:</span>Sort=<span style="color: #0033ff; font-weight: bold;">new</span> Sort &nbsp; &nbsp;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
sortValue.fields = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> SortField<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;user_name&quot;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">new</span> SortField<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;course_name&quot;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;<br />
privilegesCollection.<span style="color: #004993;">sort</span>=sortValue;<br />
privilegesCollection.refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div></td></tr></tbody></table></div>
<p><strong>Remember </strong></p>
<ul>
<li> you must sort the XmlListCollection if you want to user IViewCursor&#8217;s methods on it&#8230;otherwise flash will throw a runtime error saying that the collection is not sorted.</li>
<li>The sort must be on all the fields on which you&#8217;re going to search later. i.e here i&#8217;m searching for a row with both the coursename and user name&#8230;so, i must sort XMLListCollection on both username and coursename fields. If i sort it on just course name or user name and later search on both criteria, flex will return true for for any row with containing just the single field on which i&#8217;ve sorted &#8230; let&#8217;s assume that i&#8217;ve sorted on just the username liket this:</li>
</ul>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">privilegesCollection.<span style="color: #004993;">source</span>=e.result.row;<br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> sortValue<span style="color: #000000; font-weight: bold;">:</span>Sort=<span style="color: #0033ff; font-weight: bold;">new</span> Sort &nbsp; &nbsp;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
sortValue.fields = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> SortField<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;user_name&quot;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;<br />
privilegesCollection.<span style="color: #004993;">sort</span>=sortValue;<br />
privilegesCollection.refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>and then i search the collection usign IViewCursor&#8217;s findAny method like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> searchObj<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
searchObj.user_name = usersListBox.selectedItem.user_name;<br />
searchObj.course_name =coursesListBox.selectedItem.course_name;<br />
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>cursor.findAny<span style="color: #000000;">&#40;</span>searchObj<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;found&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0033ff; font-weight: bold;">else</span><br />
<span style="color: #000000;">&#123;</span><br />
Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;not found&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>then flex will show found Alert when ever you select a user present in the collection and any course&#8230;still confused?? watch this example:</p>
<p><a href="http://ravimarella.com/XmlListCollection/XMLListCollectionSearch.html" target="_blank">http://ravimarella.com/XmlListCollection/XMLListCollectionSearch.html</a></p>
<p>So you must sort the collection on all the fields for which you&#8217;re going to search otherwise the results will not be as expected.</p>
<p>Hope that post helps someone. Leave a comment if anypart of the post is still confusing..</p>
<p>Happy Flexing&#8230;<img class="wpml_ico" src="http://ravimarella.com/getriaed/wp-content/plugins/wp-monalisa/icons/wpml_mail.gif" alt="" /></p>
<p>Ravi.</p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://ravimarella.com/getriaed/2009/07/01/searching-flex-xmllistcollection-using-iviewcursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
