Copy link to clipboard
Copied
I am using coldfusion for my dataservice (FLOWTESTService1). This code does 2 things - 1. passes URL query string to cf data service, and 2. queries cf data service via a button and textbox.
The problem is that I need to check for empty results set when the cf data source gets queried.
That is what I am trying to accomplish here: if (getFLOWTESTResult != null && getFLOWTESTResult.lastResult != null){
Alert.show("No flow test data for this fire hydrant.");
}else {
This works but it fires the Alert.show("No flow.... all the time, even when I know there are valid records that should be returned.
Any help is much appreciated. Thanks.
Will
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:flowtestservice1="services.flowtestservice1.*" xmlns:valueObjects="valueObjects.*"
initialize="init()" width="1066" pageTitle="City of Durham - Fire Hydrant Flow Test Card">
<fx:Style source="FireFlow2.css"/>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var PRESSID:String = "03707";
private function init(): void
{
if (getFLOWTESTResult != null && getFLOWTESTResult.lastResult != null){
Alert.show("No flow test data for this fire hydrant.");
}else {
PRESSID = this.parameters.PRESSID;
getFLOWTESTResult.token = fLOWTESTService1.getFLOWTEST(PRESSID);
}
}
protected function button_clickHandler(event:MouseEvent):void
{
//if (fLOWTESTService1 != null) {
//Alert.show("No flow test data for this fire hydrant.");
//}else {
getFLOWTESTResult.token = fLOWTESTService1.getFLOWTEST(pRESSIDTextInput.text);
//}
}
private function dateFormat(item:Object, column:DataGridColumn):String{
return dateFormatter.format(item [column.dataField]);
}
]]>
</fx:Script>
<fx:Declarations>
<flowtestservice1:FLOWTESTService1 id="fLOWTESTService1" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="getFLOWTESTResult" result="customDatatype = getFLOWTESTResult.lastResult[0] as CustomDatatype"/>
<valueObjects:CustomDatatype id="customDatatype"/>
<mx:DateFormatter id="dateFormatter"
formatString="MM-DD-YYY"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Form y="46" defaultButton="{button}" borderAlpha="0.5" cornerRadius="0" dropShadowVisible="true" borderColor="#A24E4E" x="258">
<mx:FormItem label="Hydrant ID:">
<s:TextInput id="pRESSIDTextInput"/>
</mx:FormItem>
<s:Button label="Get FLOW TEST" id="button" click="button_clickHandler(event)"/>
<mx:Form borderAlpha="0.5">
<mx:FormHeading label="Results:"/>
<mx:FormItem label="Hydrant ID:">
<s:Label id="pRESSIDLabel" text="{customDatatype.PRESSID}"/>
</mx:FormItem>
<mx:FormItem label="Date:">
<mx:DateField enabled="false" id="dATEDateField" selectedDate="{customDatatype.DATE}"/>
</mx:FormItem>
<mx:FormItem label="Time:" contentBackgroundAlpha="1.0">
<s:Label id="tIMELabel" text="{customDatatype.TIME}"/>
</mx:FormItem>
<mx:FormItem label="Location 1:">
<s:Label id="lOC1Label" text="{customDatatype.LOC1}"/>
</mx:FormItem>
<mx:FormItem label="Location 2:">
<s:Label id="lOC2Label" text="{customDatatype.LOC2}"/>
</mx:FormItem>
<mx:FormItem label="Flow (gpm):">
<s:Label id="fLOWLabel" text="{customDatatype.FLOW}"/>
</mx:FormItem>
<mx:FormItem label="Static (psi):">
<s:Label id="sTATICLabel" text="{customDatatype.STATIC}"/>
</mx:FormItem>
<mx:FormItem label="Residual (psi):">
<s:Label id="rESIDUALLabel" text="{customDatatype.RESIDUAL}"/>
</mx:FormItem>
<mx:FormItem label="PRESLOC">
<s:Label id="pRESLOCLabel" text="{customDatatype.PRESLOC}"/>
</mx:FormItem>
<mx:FormItem label="Q20 (gpm):">
<s:Label id="q20Label" text="{customDatatype.Q20}"/>
</mx:FormItem>
<mx:FormItem label="FLOWID">
<s:Label id="fLOWIDLabel" text="{customDatatype.FLOWID}"/>
</mx:FormItem>
<mx:FormItem label="FLOWLOC">
<s:Label id="fLOWLOCLabel" text="{customDatatype.FLOWLOC}"/>
</mx:FormItem>
</mx:Form>
</mx:Form>
<mx:DataGrid x="72" y="549" id="dataGrid" dataProvider="{getFLOWTESTResult.lastResult}" width="904" height="160" editable="false" variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn headerText="PRESSID" dataField="PRESSID" wordWrap="false"/>
<mx:DataGridColumn headerText="Date" dataField="DATE" labelFunction="dateFormat"/>
<mx:DataGridColumn headerText="TIME" dataField="TIME"/>
<mx:DataGridColumn headerText="LOC1" dataField="LOC1" wordWrap="true"/>
<mx:DataGridColumn headerText="LOC2" dataField="LOC2" wordWrap="true"/>
<mx:DataGridColumn headerText="FLOW" dataField="FLOW"/>
<mx:DataGridColumn headerText="STATIC" dataField="STATIC"/>
<mx:DataGridColumn headerText="RESIDUAL" dataField="RESIDUAL"/>
<mx:DataGridColumn headerText="PRESLOC" dataField="PRESLOC" wordWrap="true"/>
<mx:DataGridColumn headerText="Q20" dataField="Q20"/>
<mx:DataGridColumn headerText="FLOWID" dataField="FLOWID"/>
<mx:DataGridColumn headerText="FLOWLOC" dataField="FLOWLOC" wordWrap="true"/>
</mx:columns>
</mx:DataGrid>
<mx:ColumnChart x="594" y="117" id="columnchart1" dataProvider="{getFLOWTESTResult.lastResult}" showDataTips="true" width="431" height="373">
<mx:series>
<mx:ColumnSeries displayName="Flow" yField="FLOW" id="columnSeries"/>
<mx:ColumnSeries id="columnSeries4" displayName="Q20" yField="Q20"/>
</mx:series>
<mx:horizontalAxis>
<mx:CategoryAxis id="categoryAxis" categoryField="DATE"/>
</mx:horizontalAxis>
</mx:ColumnChart>
<mx:Legend dataProvider="{columnchart1}"/>
<mx:Image x="103" y="96" source="http://localhost:8500/FireFlow2-debug/durhamlogo.PNG"/>
<s:RichText x="72" y="261" text="*This information represents flows and pressures at one specefic time. These parameters constantly fluctuate. Designers should use appropriate factors of sfety when using this information for design purposes." width="151" height="162" verticalAlign="middle" textAlign="center"/>
<s:RichText x="171" y="11" text="Fire Hydrant Flow Test Card" fontSize="24" verticalAlign="middle" textAlign="center" fontWeight="bold"/>
<s:Label x="72" y="529" text="Flow Test History:" fontWeight="bold" fontSize="14"/>
</s:Application>
Copy link to clipboard
Copied
You probably need to check for 0 records. The check != null might be true always, what is the the value of lastResult, is it an array with 0 records or null?
Thanks
-Sunil
Copy link to clipboard
Copied
I am not sure what is the value of the lastResult.
Maybe it is 0.
If I want to check it for 0 I assume this is correct --> if (getResult.lastResult == 0)
Do you know how I could check for a specific value in the array?
For instance if I wanted to check one of the fields, "FLOW" for a specific value or a condition how can I do that?
if (getResult.lastResult[0].FLOW == 150) or if (getResult.lastResult[0].FLOW > 0)
I have tried these but it doesn't work.
Thanks.
Will
Copy link to clipboard
Copied
You can do something like this...if you know the return value is always going to be an arraycollection
If(getResult.lastResult != null)
{
Var myresult:ArrayCollection;
myresult = getResult.lastResult as ArrayCollection;
if(myresult.length > 0)
....
Else
....
}
Else
{
...
}
Copy link to clipboard
Copied
SunilAdobe,
I tried using your suggestion but I am getting 2 sytax errors:
Description Resource Path Location Type
1071: Syntax error: expected a definition keyword (such as function) after attribute Var, not myresult.
1084: Syntax error: expecting rightbrace before semicolon.
errors on this line: Var myresult:ArrayCollection;
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.EventListenerRequest;
private var PRESSID:String = "0";
private function init(): void
{
PRESSID = this.parameters.PRESSID;
getFLOWTESTResult.token = fLOWTESTService1.getFLOWTEST(PRESSID);
if (getFLOWTESTResult.lastResult!=null) {
Var myresult:ArrayCollection;
myresult=getFLOWTESTResult.lastResult as ArrayCollection;
if(myresult.length>0)
Alert.show("Hey there is data.");
}else {
Alert.show("PRESSID is 0");
}
}
protected function button_clickHandler(event:MouseEvent):void
{
//if (fLOWTESTService1 != null) {
//Alert.show("No flow test data for this fire hydrant.");
//}else {
getFLOWTESTResult.token = fLOWTESTService1.getFLOWTEST(pRESSIDTextInput.text);
//}
}
private function dateFormat(item:Object, column:DataGridColumn):String{
return dateFormatter.format(item [column.dataField]);
}
]]>
</fx:Script>
Copy link to clipboard
Copied
The uppercase V in Var is causing the issue, please use var, and import mx.collections.ArrayCollection;
These are syntax errors, recommend you to clear all syntax errors and try out.
-Sunil