apache-flexrefreshflex-datagrid

Flex datagrid not updated properly


I have two tables: Person {pID, pName, deptID} and Departments {deptID,deptName} An SQL statement like this gets me the name of a person and the department name:

SELECT pName, departments.deptName FROM people INNER JOIN people.deptID = departments.deptID;

The above works fine. I have a Flex DropDownList that is populated with deptNames. When I click the submit button, I am able to obtain the ID of the selected department without problem:

protected function button_clickHandler(event:MouseEvent):void
   {
    person.pName=pNameTextInput.text;
    person.deptID=pDepartmentDropDownList.selectedItem.deptID; //ID of selected department obtained correctly.
    if (person.pID == 0)
    {
     createPersonResult.token=personService.createPerson(person);
    }
    else
    {
     updatePersonResult.token=personService.updatePerson(person);
    }
  }

I have a createPersonresult Handler that attempts to update the datagrid when a person is added. The datagrid is updated with the new added person, but in the department column, I get the ID of the department chosen from the dropdownlist. I need to reload the flash app to get the datagrid refreshed to display the deptName.

Something is missing in this createPerson result Handler. Google didn't provide much help.

   protected function createPersonResult_resultHandler(event:ResultEvent):void
   {
    currentState="PeopleDetails";
    person.pID=event.result as int;
    peopleDg.dataProvider.addItem(person); //the problem might be here, more below.
    peopleDg.setSelectedIndex(peopleDg.dataProvider.getItemIndex(person));
    peopleDg.ensureCellIsVisible(peopleDg.selectedIndex);
   }

From the comment above, I see that adding person will indeed add the attributes of the person object to the datagrid, except that one attribute is a foreign ID (deptID) from departments.


Solution

  • I think you need to set your deptName property since you aren't getting it from the join when it's being added in the interface. So something like this should do the trick I think?

    EDIT: for 4.5 dropdown instead of combobox

    protected function button_clickHandler(event:MouseEvent):void
    {
        person.pName=pNameTextInput.text;
        person.deptID=pDepartmentDropDownList.selectedItem.deptID; //ID of selected department obtained correctly.
        person.deptName = pDepartmentDropDownList.selectedItem.deptName;
        if (person.pID == 0)
        {
            createPersonResult.token=personService.createPerson(person);
        }
        else
        {
            updatePersonResult.token=personService.updatePerson(person);
        }
    }