Expand my Community achievements bar.

Database

Avatar

Level 2
Hi

i am having one issue.right now we are developing a shopping
cart.in that application i need to populate the values from the
database in the combobox(Getting the values from the databases and
set in the combobox).

i have succeeded in connecting the flex application to the
database but i dont know how to get the values from the database to
the<mx:combobox> and i need a code for that.



Thanks

Vasibe
3 Replies

Avatar

Level 2
You'll want to create a Java object which exposes a method to
get the values from the database. From mxml, you'll use the
RemoteObject tag to call that method on the server. The result
handler for the RemoteObject will bind the values of the result to
the <mx:combobox> tag.



Please see the documentation for using the RemoteObject
tag.

Avatar

Level 3
As Cathy said, you should able to find a good documentation
from the remoteobject & combobox tag. combobox takes array of
objects as dataprovider. You can specify the field which you want
to use by specifying it in the labelField attribute

Example:

<?xml version="1.0"?>



<mx:Application width='800' height='800' xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="setup()">

<mx:RemoteObject destination="qa.echoservice.Echo"
id="ro"/>

<mx:Script>

<![CDATA[

private function setup():void

{


ro.echoObjects([{label:"MA",value:"Massecussetts"},{label:"NY",value:"New
York"}]);

}

]]>

</mx:Script>

<mx:ComboBox dataProvider="{ro.echoObjects.lastResult}"
labelField="value"/>

</mx:Application>



By removing the labelField="value", combobox shows MA,NY.
Otherwise, combobox use value field . You should see Massachusetts,
New York in the box



Please look it up from the doc for more details



Hope it help!

William Chan

Avatar

Level 2
hi,

thanks william and cathy .now its working.



Vasibe