Thanks for your time on this Martin - it's certainly appreciated.

A bit more context to my scenario...

I'm trying to build a generic set of CRUD screens against a simple database.
I'm using simple json schema's to build the UI in a generic way. The data
binding and controllers are perfect for this - once I set the model from a
remote json store the controller takes care of the rest.

In my cut down example...

My main table is called Job and it has two related tables jobStatus and
jobType (Job has one of each).
jobStatus and jobType are received as a json array and they are turned into
a binded select list.

When I retrieve a Job record, the server side returns a json instance of all
the properties including the jobStatus and jobType - I can configure the
server (I'm using Grails) to return the related records in full or just
return the primary key.

What would be ideal is for me to be able to set the Job record from my json
store directly to the form controller model without having to know any
special details about the form.

selectedModel = <some item from my json store>;
formController.setModel(selectedModel);

This works for all primitive properties but because the select list value is
another object model there is no way that the current controllers can work
out what to select unless I manually set them as you previously suggested. 

selectedModel = <some item from my json store>;
selectedMode.setJobType(<someType used by the list controller>);
selectedMode.setJobStatus(<someStatus used by the list controller>);
formController.setModel(selectedModel);

By the way, if the select list was a list of primitive values - it would
actually work without having to manually set the values as per the example
above.

To remove that manual step of having to set the values, the selection could
be given a "hint" for when the select items are objects and not primitives.
This would be something like an identity property or method. A helper
function would then traverse the list until it found a match.

EG when adding a widget to the form controller it could be part of an
options param

form.add(selectListWidgetWithBindedController, "Job Type", { identity : "id"
} );

The controller bindings could have a finder function that does the match...
    findItemByProp : function(value, list, prop)
    {
        try
        {
            // basic param checks
            if (prop == null) prop = 'id';
            if (value == null) throw new Error("value cannot be empty");
            if (list == null) throw new Error("list cannot be empty");

            for (var i=0; i<list.getLength(); i++)
            {
                if (list.getItem(i).get[prop]() == value) { return
list.getItem(i) }
            }
            return null;
        }
        catch(e) {this.error(arguments.callee.displayName + ' : ' + e)}

        return null;
    },


// example job record
    jobList : {
        "message": "Done",
        "status": 0,
        "list":
            [
                {
                  "startDate": new Date(1230814800000),
                  "jobType": {  // example of a deep copy of a related
record
                    "id": 3,
                    "name": "Child Care",
                    "lastUpdated": new Date(1278922130558),
                    "dateCreated": new Date(1278922130558)
                  },
                  "jobStatus": { // example of a shallow copy of a related
record - primary key only
                    "id": 1
                  },
                  "dateCreated": new Date(1278922130942),
                  "useClientAddress": true,
                  "completionDate": null
                }
            ]
    },

//example jobType List that is binded to a select list for use against the
Job record form controller.
    jobTypeList : {
        "message": "Done",
        "status": 0,
        "list":
            [
                {
                  "id": 3,
                  "name": "Child Care",
                  "lastUpdated": new Date(1278922130558),
                  "dateCreated": new Date(1278922130558)
                }
            ]
    },


Not sure if I rambled on too much... I hope I didn't confuse the situation
even more!!!

-- 
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Form-Binding-with-List-Binding-tp5121281p5292151.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to