views:

415

answers:

1

Main Goal : Select a school listed in the first datagrid, and display all the student records /details of that school in the next datagrid. But, since datagrid is editable and requirement mentions : "Use a Wrapper class around the object to get the data, set the same and save. Ensure wrapper is bindable to take into consideration the updates being made to datagrid text fields."

I have an object which is a type of a Data Access Objects i.e. DO.

mySchool:mySchoolDO.

The mySchoolDO is an actionScript class of following code :

public class mySchoolDO

{
        public var schoolName:String;
        public var schoolLocation:String;
        public var schoolStudents:ArrayCollection; 
        // Array of myStudentDO instances

}

The above has an array collection of students called schoolStudents which accesses the myStudentDO.as class as described below.


myStudent:myStudentDO.

The myStudentDO.as is an actionScript class of following code :

public class myStudentDO implements IExternalizable 
{
        [Bindable]      public var studentID: String;
        [Bindable]      public var studentCourses: Array
        [Bindable]      public var studentPhone:Number;
        [Bindable]      public var studentGender:Boolean;

            public function readExternal(input:IDataInput):void {
            studentID = SerializationUtils.readNullableString(input);
            studentCourses = SerializationUtils.readNullableString(input);
            studentPhone = SerializationUtils.readStringList(input);
            studentGender = SerializationUtils.readNullableString(input);
}


In my main mxml application. I do the following :

1> Get all schools array. Instantiate a school object and get school data. 2> Using school object access all studentsDO data and store as an ARRAY OF OBJECTS.


private function availableSchools(schools:Array): void
{
     mySchools=schools;
     loadSchools();
}

private function loadSchools():void
{
   for(var z:int =0; z

Once a school is clicked, an ItemClick Event is fired which takes the school and then displays all the school students data.

private function itemClickEvent(event:ListEvent):void
{
    _school = event.currentTarget.selectedItem;
     showSchoolStudents(_school);
    }

private function showSchoolStudents(school:mySchoolDO) 
{
   for(var b:int=0; b<(school.schoolStudents).length;b++) 
    { 
        schoolDatagridProvider.push(school.schoolStudents[b]); 
    }
       dgOfSchool.dataProvider = schoolDatagridProvider; 
       dgOfSchool.invalidateList(); 
}

The showSchoolStudents will display all the details of students on to the datagrid. But, my datagrid is editable. And, I want to use WRAPPER CLASS around this object such that

a> I can retrieve individual values as present in studentsDO i.e. studentID, studentCourses, studentGender, studentPhone.

b> I shouldbe able to set the values as they are updated in the visual datagrid.

c> Finally save all the data and submit on submit click.


Please help with code. It will be highly appreciated.

Thanks.

A: 

Looks like you're really just starting out with Flex.

Suggestion: read the documentation. There's plenty of examples of the basic thing you're trying to do here which is to have an editable Grid that displays data coming from the server.

Some key concepts:

Make sure you're using an ArrayCollection as the dataProvider to the Grid, not an Array. ArrayCollections provide the change-notification machinery you'll invariably want with this use case.

Make sure your DO model classes are all Bindable. Looks like you're only making the Student properties bindable at the moment. Make the School bindable as well.

Make the reference from School to the collection of Students an ArrayCollection, not an Array.

Follow convention and use initial caps in Class names. i.e. MyStudentDO, MySchoolDO

Tell the DataGrid that you want to allow item editing.

But, in all seriousness, read the docs. There's plenty of examples available.

verveguy