Flex 3: Filtering an XML datagrid using multiple list filters: No longer working!

Hi,

A while ago I asked a question regarding using multiple filters, and got my code working - see below.

Now, for some reason, when testing the flex application, it crashes the browser (IE and Firefox).  

Can anyone see what's wrong with this code? I've got the same problem on another project where I've tried to build from scratch doing the same thing - either my function won't work due to not returning a value or it does build and then crashes.

Thanks,
John
?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
 
    <mx:Script>
        <![CDATA[
            import mx.collections.*;
            import mx.events.ListEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            import flash.events.Event;
            import mx.events.ItemClickEvent;
            
            [Bindable]public var lobsArray:ArrayCollection;
            [Bindable]public var typesArray:ArrayCollection;
			[Bindable]public var documentsArray:ArrayCollection;
			private var selectedLob:String;
			private var selectedType:String;
					
			private function init():void {
				lobsXML.send();
				typesXML.send();
				documentsXML.send();
			}
			
			private function httpResultHandler(event:ResultEvent):void {
				typesArray = event.result.types.type;
			}
			
			private function httpResultHandler2(event:ResultEvent):void {
				lobsArray = event.result.lobs.lob;
			}
				
			private function httpResultHandler3(event:ResultEvent):void {
				documentsArray = event.result.dataset.document;
			}
			
			private function httpFaultHandler(event:FaultEvent):void {
			Alert.show("There was a problem","Error");
			}
 
			public function filterLob(event:ListEvent):void {
				selectedLob = lobSelectList.selectedItem.name;
				documentsArray.filterFunction=lobFilter;
				documentsArray.refresh();
			}
			
			public function filterType(event:ListEvent):void {
				selectedType = typeSelectList.selectedItem.name;
				documentsArray.filterFunction=typeFilter;
				documentsArray.refresh();
			}	
				
			public function lobFilter(item:Object):Boolean {
				
				if (selectedType == null) {
					return item.policyClass == selectedLob
				} else {
				return item.policyClass == selectedLob && item.docType == selectedType;
				}
			}
			
			public function typeFilter(item:Object):Boolean {
				if (selectedLob == null) {
					return item.docType == selectedType
				} else {
				return item.docType == selectedType && item.policyClass == selectedLob;
				}
			}
 
        ]]>
    </mx:Script>
 
	<mx:HTTPService id="typesXML" url="assets/types.xml" fault="httpFaultHandler(event)" result="httpResultHandler(event)" />
	<mx:HTTPService id="lobsXML" url="assets/lobs.xml" fault="httpFaultHandler(event)" result="httpResultHandler2(event)" /> 
	<mx:HTTPService id="documentsXML" url="assets/documents.xml" fault="httpFaultHandler(event)" result="httpResultHandler3(event)" />
 
    <mx:Panel title="Johns Dividing Boxes Example" width="800" height="600" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
 
        <mx:VDividedBox width="100%" height="90%">
 
<!-- Upper Canvas Start -->
            <mx:Canvas label="Higher Canvas" width="100%" height="100%">
	            
	            <mx:HDividedBox width="100%" height="100%">
				
				<mx:Panel id="lobSelectPanel" width="40%" height="100%">
					<mx:Label text="Please Select a Line of Business" />
					<mx:List id="lobSelectList" dataProvider="{lobsArray}" width="100%" change="filterLob(event)"
							selectable="true" allowMultipleSelection="false" borderStyle="none" labelField="name" />
				</mx:Panel>
				
				<mx:Panel id="typeSelectPanel" width="40%" height="100%">
					<mx:Label text="Please Select a type of document" />
					<mx:List id="typeSelectList" dataProvider="{typesArray}" width="100%" 
						change="filterType(event)" allowMultipleSelection="false" borderStyle="none" labelField="name" />
				</mx:Panel>
	            
	        	</mx:HDividedBox>
            </mx:Canvas>
<!-- Upper Canvas Ends -->
            
<!-- Lower Canvas Starts -->
            <mx:Canvas label="Lower Canvas" width="100%" height="100%" backgroundColor="#eff1ec">
            	<mx:Panel id="documentDisplayPanel" width="100%" height="100%">
            	    <mx:DataGrid id="documentDisplayList" width="100%" height="100%" dataProvider="{documentsArray}" >
	                	<mx:columns>
	                		<mx:DataGridColumn dataField="description" headerText="Title" />
	                		<mx:DataGridColumn dataField="policyClass" headerText="Policy Class" />
	                		<mx:DataGridColumn dataField="docType" headerText="File Type" />
	                		<mx:DataGridColumn headerText="Doc Link" dataField="docURL" />
	                	</mx:columns>
	                </mx:DataGrid>
                </mx:Panel>
            </mx:Canvas>
<!-- Lower Canvas Ends -->
 
        </mx:VDividedBox>
 
	<mx:Text />
 
    </mx:Panel>
 
</mx:Application>
 
<!-----  types.xml  ----->
 
<types>
	<type>
		<name>Policy Wording</name>
		<id>pol</id>
	</type>
	<type>
		<name>Endorsement</name>
		<id>end</id>
	</type>
	<type>
		<name>Risk Management Guide</name>
		<id>rmg</id>
	</type>
	<type>
		<name>Risk Appetite</name>
		<id>ris</id>
	</type>
	<type>
		<name>UW Statement</name>
		<id>uws</id>
	</type>
	<type>
		<name>Policy Summary</name>
		<id>sum</id>
	</type>
	<type>
		<name>Pricing Approach</name>
		<id>pri</id>
	</type>
	<type>
		<name>Other</name>
		<id>oth</id>
	</type>
</types>
 
<!------------ Line of business (lobs) xml ------>
 
<lobs>
	<lob>
		<name>Property</name>
		<id>pr</id>
	</lob>
	<lob>
		<name>Liability</name>
		<id>li</id>
	</lob>
	<lob>
		<name>Motor</name>
		<id>mo</id>
	</lob>
	<lob>
		<name>Engineering</name>
		<id>en</id>
	</lob>
	<lob>
		<name>Motor Fleet</name>
		<id>mf</id>
	</lob>
	<lob>
		<name>ProFin</name>
		<id>pf</id>
	</lob>
	<lob>
		<name>Small Business</name>
		<id>sb</id>
	</lob>
	<lob>
		<name>Motor Trade</name>
		<id>mt</id>
	</lob>
</lobs>
 
 
<!------------ documents.xml (for datagrid) ------>
 
<dataset>
	<document>
		<docType>Aide Memoire</docType>
		<alpha>A</alpha>
		<status>Live</status>
		<policyClass>Liability</policyClass>
		<system>UKRIS</system>
		<description>Abuse Aide Memoire</description>
		<referenceNo>na</referenceNo>
		<releaseDate>2005-08</releaseDate>
		<replacedDate/>
		<replacementRef/>
		<locallyHeld>No</locallyHeld>
		<contact/>
		<docURL>http://kite.uk.rsa-ins.com/prod/kite/techcontainer.nsf/luresources/documentlibrary_Aide Memoire/$file/abuseaidememoire.pdf</docURL>
		<imageURL/>
	</document>
	<document>
		<docType>Aide Memoire</docType>
		<alpha>A</alpha>
		<status>Live</status>
		<policyClass>Liability</policyClass>
		<system>UKRIS</system>
		<description>Abridged Report Aide Memoire</description>
		<referenceNo>na</referenceNo>
		<releaseDate>2005-07</releaseDate>
		<replacedDate/>
		<replacementRef/>
		<locallyHeld>No</locallyHeld>
		<contact/>
		<docURL>http://kite.uk.rsa-ins.com/prod/kite/techcontainer.nsf/luresources/documentlibrary_Aide Memoire/$file/abridgedreportaidememoire.pdf</docURL>
		<imageURL/>
	</document>
	<document>
		<docType>Aide Memoire</docType>
		<alpha>A</alpha>
		<status>Live</status>
		<policyClass>Liability</policyClass>
		<system>UKRIS</system>
		<description>Asbestos Aide Memoire</description>
		<referenceNo>na</referenceNo>
		<releaseDate>2004-12</releaseDate>
		<replacedDate/>
		<replacementRef/>
		<locallyHeld>No</locallyHeld>
		<contact/>
		<docURL>http://kite.uk.rsa-ins.com/prod/kite/techcontainer.nsf/luresources/documentlibrary_Aide Memoire/$file/asbbulletinaidememoirejune04.pdf</docURL>
		<imageURL/>
	</document>
	<document>
		<docType>Aide Memoire</docType>
		<alpha>E</alpha>
		<status>Live</status>
		<policyClass>Engineering</policyClass>
		<system>UKRIS</system>
		<description>Engineering Computer Survey Aide Memoire</description>
		<referenceNo>na</referenceNo>
		<releaseDate>2005-04</releaseDate>
		<replacedDate/>
		<replacementRef/>
		<locallyHeld>No</locallyHeld>
		<contact/>
		<docURL>http://kite.uk.rsa-ins.com/prod/kite/techcontainer.nsf/luresources/documentlibrary_Aide Memoire/$file/EngineeringCompSurveyAideMemoire.pdf</docURL>
		<imageURL/>
	</document>
</dataset>

Open in new window

RSA_KM_TEAMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mplordCommented:
I've compiled this example and (assuming you manually copy your assets folder with XML files to the build destination path) works fine with no crashes. That's on Flash Player 9,0,124,0.

However it doesn't help that your documents data set has only documents of type Aide Memoire, which is not a selectable value in your types list, so couldn't try out the double filter without modifying your documents data set a little. The double filter works fine though.

Having Flash Player 'crash' IE or Firefox does not sound right - at most it should issue a runtime error, but I think Adobe are pretty careful to ensure Flash can't bring down your browser - maybe you've got a corrupt installation somewhere, are you able to test on another machine?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RSA_KM_TEAMAuthor Commented:
Hi mplord, thanks for responding.

I did try this on another machine, but that was copying the archive project over.  I'll try a new project and copying the code / xml files from scratch see if that solves it.  (I have a more complete dataset to use with various docTypes etc).

I'll post back later on today. Thanks again.
0
RSA_KM_TEAMAuthor Commented:
Just tried on a colleagues machine, it isn't crashing the browser, but this is the error we are getting:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at doclib/lobFilter()[C:\adobeflextraining\doclib\src\doclib.mxml:57]
      at mx.collections::ListCollectionView/internalRefresh()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1250]
      at mx.collections::ListCollectionView/refresh()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:402]
      at doclib/filterLob()[C:\adobeflextraining\doclib\src\doclib.mxml:45]
      at doclib/__lobSelectList_change()[C:\adobeflextraining\doclib\src\doclib.mxml:90]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
      at mx.controls.listClasses::ListBase/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:8989]
      at mx.controls::List/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\List.as:2279]

We didn't manually copy the XML files over - they were copied over automatically.  

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

RSA_KM_TEAMAuthor Commented:
Further to the above and speaking with a colleague, it now appears to be working..... all we've changed was to remove the self-closing tags from the XML, into having a separate closed tag.

I assume yours worked without doing that?
0
mplordCommented:
From the XML samples you provided, yes these worked without modification when split out into seperate files.
Maybe you could provide an example of the change you describe above - 'remove the self-closing tags from the XML, into having a separate closed tag'.
0
mplordCommented:
Polite request for an update - please remember to close questions if your issue is resolved, or reply if you need further assistance ;)
0
RSA_KM_TEAMAuthor Commented:
Hi,

Apologies for the delay in coming back to this.

By removing the self closing tags, I mean I went through the documents dataset, and changed tags like <replacedRef /> with <replacedRef></replacedRef>  - once all changed this seemed to work.

I've been seeing if there's a smarter way to do this, and came across this blog entry -
http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

It seems like a much neater way of achieving my aims, though I've tried to amend his source code to use xml for the dataprovider rather than his array of objects.  On there, someone has managed to do this (Maarten, post 71 and 75, right at the bottom), but I can't seem to get it to work.  

Does this look like a cleaner way, and if so, how would I amend the dataprovider to refer to my xml?  

I realise this is asking way more than the original question, so as a relatively newcomer to Experts Exchange, happy to create a new question. I'll already by awarding the points for your help!

Thanks again,
John
0
RSA_KM_TEAMAuthor Commented:
Thanks for your help.

I've now solved this by doing it differently from the blog I posted in the last comment on the thread, but as mentioned awarding the points for you helping me get the initial example to work.

Many thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.