So on a Flex Mobile Project I am trying to bind the results from a Select SQLLite query to a view. But it is not displaying results and I get the following
warning: unable to bind to property 'myData' on class 'com.amec.controls.Text::TextListView'
From FLash Builder. Below is my view class. What is it I am missing or doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<amec:BaseAddView xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:amec="com.amec.Components.*"
creationComplete="vw_creationCompleteHandler(event)" title="TextListView">
<amec:layout>
<s:VerticalLayout horizontalAlign="center" paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5"/>
</amec:layout>
<fx:Script>
<![CDATA[
import com.amec.BaseSql;
import com.amec.MenuMessage;
import mx.events.FlexEvent;
[Bindable]private var resultArr:ArrayCollection = new ArrayCollection();
import mx.collections.ArrayCollection;
protected function vw_creationCompleteHandler(event:FlexEvent):void
{
}
private function get myData():ArrayCollection
{
var conn:BaseSql = new BaseSql();
conn.stmt.text = "SELECT DMV_VALUE_1 FROM DOMAIN_VALUE WHERE DMV_DMN_ID = :id";
x.parameters[":id"] = id;
x.sqlConnection = conn.stmt.sqlConnection;
var x:SQLStatement = new SQLStatement;
x.text = conn.stmt.text;
x.execute();
var result:Array = conn.stmt.getResult().data;
var r:ArrayCollection = new ArrayCollection();
if (result)
{
r.source = result;
return r;
} else {
return null;
}
}
]]>
</fx:Script>
<s:List id="list" top="0" bottom="0" left="0" right="0"
dataProvider="{myData}" labelField="DMV_VALUE_1">
</s:List>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
Also I am not getting any results to show up in the view.
First, set the property to be Bindable:
Since you do not have a 'set' method defined. As such, whenever the 'myData' changes you will have to manually dispatch the myDataChanged event in order for Bindable to have an affect.
I suspect that you will also have to make myData() a public property; otherwise how will the classes that make binding work be able to introspect into your custom component in order to access the property.
Overall, it looks like you are choosing a very bad implementation approach. Is it is unusual to use a get method to make a database call and process the results. It much more common to encapsulate such code out of your view; and pass the result data into the view. There are many different ways to do this. You could do it with a singleton approach, or a dependency injection framework, or dispatching events from a service class with the result data.