PsychoDazey
asked on
Refresh combobox after data is added
Hi experts -
I am using flex builder 2. I have a page with a combobox, the dataProvider is an array collection that gets populated from a database; when you double-click the combo box it opens a pop up. You then enter the name of a new supplier in the pop up and it adds it to the database. Next the pop up closes and the webservice is called to re-populate the ArrayCollection. I am trying to get the combo-box to refresh so it shows the new data, but it won't. I checked to see that the data is added correctly but it wont show up in the list until you completely close the app and re-open it again. I have attached the code for the combobox and the code that I am using to re-populate the Array Collection.
I am using flex builder 2. I have a page with a combobox, the dataProvider is an array collection that gets populated from a database; when you double-click the combo box it opens a pop up. You then enter the name of a new supplier in the pop up and it adds it to the database. Next the pop up closes and the webservice is called to re-populate the ArrayCollection. I am trying to get the combo-box to refresh so it shows the new data, but it won't. I checked to see that the data is added correctly but it wont show up in the list until you completely close the app and re-open it again. I have attached the code for the combobox and the code that I am using to re-populate the Array Collection.
<mx:Binding source="cboSupplier.dataProvider as ArrayCollection" destination="obj.SupplierDepartmentTypes"/>
<mx:ComboBox x="191" y="30" id="cboSupplier" dataProvider="{obj.SupplierDepartmentTypes}" labelField="Value" width="200"
doubleClickEnabled="true" doubleClick="this.supplierDepartmentDoubleClicked(KeyPair(cboSupplier.selectedItem).Name);"
change="obj.UpdateRmr(Program.currentUser, 'Vendor_Dept', String(KeyPair(cboSupplier.selectedItem).Name), obj.myCursor.current.RMRNum, 0);">
</mx:ComboBox>
public function supplierDepartmentDoubleClicked(supplierDepartmentType:String):void
{
var popup:NewSupplierDepartmentDialog = PopUpManager.createPopUp(this,NewSupplierDepartmentDialog,true) as NewSupplierDepartmentDialog;
PopUpManager.centerPopUp(popup);
//check to see if there is a listener for pop-up manager
//obj.GetSuppliers();
}
public function GetSuppliers():void
{
var ws:WebService = Program.m_webServiceManager.getWebservice();
ws.GetSupplierDepartments.addEventListener(ResultEvent.RESULT,LoadSuppliers);
ws.GetSupplierDepartments();
}
public function LoadSuppliers(e:ResultEvent):void
{
var dataSet:DataSet = new DataSet(String(e.result));
if(dataSet.HasErrors())
{
Alert.show(dataSet.GetErrorAt(0));
}
else
{
this.SupplierDepartmentTypes=new ArrayCollection;
var dataTable:DataTable = dataSet.GetTableAt(0);
var keyPair:KeyPair = new KeyPair();
keyPair.Name = "0";
keyPair.Value = "Select Supplier";
this.SupplierDepartmentTypes.addItem(keyPair);
for(var index:int=0;index<dataTable.RowCount();index++)
{
var row:DataRow = dataTable.GetRowAt(index);
keyPair = new KeyPair();
keyPair.Name = String(row.GetValue(0));
keyPair.Value = String(row.GetValue(1));
this.SupplierDepartmentTypes.addItem(keyPair);
}
//this.SupplierDepartmentTypes.enableAutoUpdate();
SupplierDepartmentTypes.refresh();
}
}
Is SupplierDepartmentTypes [Bindable]?
ASKER
yes, here is the declaration:
[Bindable]
public var SupplierDepartmentTypes:Ar rayCollect ion;
[Bindable]
public var SupplierDepartmentTypes:Ar
Are you sure its gets to line 33 in you code sample. Put a debug point there and see if the ws result is commign back.
ASKER
yes, i had added an alert to display "made it to refresh" after the SupplierDepartmentTypes.re fresh();
and it displayed.
and it displayed.
Can I ask why u have the binding on line 1?
ASKER
I thought I needed it there...let me try taking it out.
public function LoadSuppliers(e:ResultEven t):void
This function is the result handeler for the ws, but in the function I don't see you access e to get the data out.
This function is the result handeler for the ws, but in the function I don't see you access e to get the data out.
ASKER
No, still doesnt refresh. I have other datagrids and lists that work using this method. I just cant get this one to work.
ASKER
I do that right here:
var dataSet:DataSet = new DataSet(String(e.result));
var dataSet:DataSet = new DataSet(String(e.result));
OK
Why do you have this:
obj.SupplierDepartmentType s
as the dataprovider not just
SupplierDepartmentTypes
Why do you have this:
obj.SupplierDepartmentType
as the dataprovider not just
SupplierDepartmentTypes
ASKER
the calls to the webservice and the declarations for the array collection are in an actionscript file. I use the following code in the mxml file to reference the appropriate action script file:
import app_Code.RCDisposition;
[Bindable]
private var obj:RCDisposition = new RCDisposition();
import app_Code.RCDisposition;
[Bindable]
private var obj:RCDisposition = new RCDisposition();
OK its really odd.
Coudl it be that once you add the item and send it off that that is happening after you try get the new data?
Coudl it be that once you add the item and send it off that that is happening after you try get the new data?
ASKER
I dont think so...I have the pop up call the webservice that adds the new supplier. Once that is successful (I have an event to track it) it removes the pop up and calls the webservice to rebuild the array.
Let me try putting alerts in both places to make sure it looks like its happening in the right order.
Let me try putting alerts in both places to make sure it looks like its happening in the right order.
ASKER
No, thats not it either. It never refreshes the combo box...even if I add 6 new partnumbers, none of them appear until I completely close out of the app and log back in. It seems to be caching it and not letting go.
Can u paste the function where u call the ws first?
ASKER
sure...here you go
package app_Code
{
import mx.containers.TitleWindow;
import mx.rpc.soap.WebService;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import flash.events.Event;
public class NewSupplierDepartmentDialog extends TitleWindow
{
// *********** WEBSERVICE CALL METHODS ******************
public function AddNewSupplierDepartment(supplierDepartment:String):void
{
//Alert.show("Webservice called");
var ws:WebService = Program.m_webServiceManager.getWebservice();
ws.AddNewSupplierDepartment.addEventListener(ResultEvent.RESULT,AddNewSupplierDepartmentResult);
ws.AddNewSupplierDepartment(supplierDepartment);
}
// ******************************************************
// ********** WEBSERVICE RESULT METHODS ******************
private function AddNewSupplierDepartmentResult(e:ResultEvent):void
{
//Alert.show("Webservice ran");
var dataSet:DataSet = new DataSet(String(e.result));
if(dataSet.HasErrors())
{
Alert.show(dataSet.GetErrorAt(0));
}
else
{
// handle a successful add...
// show messag to user?
// show message on dialog and allow user to continue?
dispatchEvent(new Event("AddNewSupplierDepartmentWebServiceCallSuccessful",true));
}
}
// *******************************************************
}
}
Ok so instead of calling the 2nd method just call the 1st one after you add the item?
ASKER
so call it in the else statement?
After you get the pass result from the update call it at the end of that.
>> ... and it adds it to the database.
Are you sure of that one? Did you check that?
>> Next the pop up closes and the webservice is called to re-populate the ArrayCollection.
Are you sure that the newly added entry is in that re-populated ArrayCollection? Can you confirm that?
Are you sure of that one? Did you check that?
>> Next the pop up closes and the webservice is called to re-populate the ArrayCollection.
Are you sure that the newly added entry is in that re-populated ArrayCollection? Can you confirm that?
ASKER
Hi zzynx; yes i am sure it is adding it to the database.
No, I am not sure if it is in the newly populated array collection. I guess to test that I can do a row count before and after. Let me check that out and post back.
No, I am not sure if it is in the newly populated array collection. I guess to test that I can do a row count before and after. Let me check that out and post back.
>> I guess to test that I can do a row count before and after.
Even better: iterate through it and trace out some characteristic attributes so you see *what* entries there are in it.
Even better: iterate through it and trace out some characteristic attributes so you see *what* entries there are in it.
ASKER
how would i go about doing that?
From you original code sample at line 50 put a debug point on: SupplierDepartmentTypes.re fresh();
Then inspect SupplierDepartmentTypes looking for the values you are expecting.
Then inspect SupplierDepartmentTypes looking for the values you are expecting.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks- I am working on something else right now but will test this later.
ASKER
zzynx -
I apologize for leaving this open for so long. I got pulled off of this project to work on a producton issue, but will be looking into it again within the next week.
I apologize for leaving this open for so long. I got pulled off of this project to work on a producton issue, but will be looking into it again within the next week.
OK. Take your time.
Thanks for letting me know.
Thanks for letting me know.
ASKER
So after all this they decide the best solution was to automate the process of updating the drop down list so it is no longer necessary to have a user add a new item. I agree, but I wish I hadn't spent the time trying to debug my solution ;)
Thanks for the help, I'll award the points to you since you provided me with the method to test if the data was actually being refreshed.
Thanks for the help, I'll award the points to you since you provided me with the method to test if the data was actually being refreshed.
Say what? I said exactly where to put the debug point at the very least a split.
thanx 4 axxepting