Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSource API and composition relationships

    In my data model I have a composition relationship as follows:

    Code:
    class Person {
      List<Address> addresses;
      PersonName personName;
    }
    
    class Address {
      String street;
      String city;
      String state;
    }
    
    class PersonName {
      String givenName;
      String familyName;
    }
    I assume I will need a PersonDataSource and a AddressDataSource.
    I think I also need a PersonNameDataSource.

    What I am not sure of is how to define a collection field for addresses and a composite field for personName in PersonDataSource.

    Thanks for any guidance you can provide.

    #2
    It appears that DataSourceSequenceField may have a role to play in addressing my question. Problem is I cannot find enough docs describing what that field type is and how to use it. The Data Bound Calendar example shows a use but it assumes there is a foreign keyfrom composed object to parent object. In my case there is no such foreign key. The parent object simply has a collection of composed objects.

    Thanks for any guidance you can provide.
    Last edited by farrukh_najmi; 9 Mar 2009, 07:39.

    Comment


      #3
      Here is a more specific question related to this thread...

      How can I create a DataSource instance for a collection property nested within a parent DataSource?

      In my earlier example I have a PersonDataSource with a collection of Address objects composed within.

      I want to be able to create a AddressDataSource using the collection of Address objects in the PersonDataSource. How can I do that?

      Thanks for your help.

      Comment


        #4
        I see that this issue has been discussed here. I will study and experiment and post any followup questions. Thanks.

        Comment


          #5
          I am unable to make a parent child composition relationship between my PersonDataSource and my AddressDataSource as described discussed here.

          The problem is that there is no foreign key from Address to Person in my model. It is simply implied by the composition relationship. How do I handle that situation?
          Currently I am trying to populate a AddressListGrid using addressListGrid.fetchRelatedData(record, personDataSource) but the list is not being populated because there is no foreignKey from AddressDataSource to PersonDataSource.
          Is there a simple solution to my scenario?

          Here is my very simple JSON data in PersonDataSource:

          Code:
          {
             "PersonList":{
                "Person":[
                   {
                      "Address":[
                         {
                            "city":"Santa Fe",
                            "state":"NM",
                            "street":"1 Main Street"
                         },
                         {
                            "city":"Santa Ana",
                            "state":"CA",
                            "street":"10 Main Street"
                         }
                      ],
                      "id":"urn:acme:person:Joe"
                   }
                ]
             }
          }
          Here is my PersonDataSource:

          Code:
          public class PersonDataSource extends XJSONDataSource {
              public PersonDataSource() {
          	this.setDataFormat(DSDataFormat.JSON);
                  this.setDataTransport(RPCTransport.SCRIPTINCLUDE);
                  this.setRecordXPath("/PersonList/Person");
          
                  DataSourceTextField objectId = new DataSourceTextField("id", "Id");
                  objectId.setValueXPath("id");
                  objectId.setPrimaryKey(true);
          
                  this.setFields(objectId);
              }    
          }
          Here is my AddressDataSource:

          Code:
          public class AddressDataSource extends DataSource {
              public AddressDataSource(DataSource parentDS) {
          	this.setDataFormat(DSDataFormat.JSON);
                  this.setRecordXPath("/Address");
          
                  //Also tried following XPATH with no luck
                  //this.setRecordXPath("/PersonList/Person/Address");
          
                  DataSourceTextField streetField = new DataSourceTextField("street");
                  DataSourceTextField stateField = new DataSourceTextField("state");
                  DataSourceTextField cityField = new DataSourceTextField("city");
          
                  this.setFields(streetField, cityField, stateField);
              }
          }
          Last edited by farrukh_najmi; 10 Mar 2009, 06:00.

          Comment


            #6
            The next thing I tried is to simply replace the addressListGrid.fetchRelatedData(record, personDataSource) call with the following to add the Person record to the AddressDataSource using:

            Code:
            addressDataSource.addData(record);
            and changing the recordXPath in AddressDataSource to "/Person/Address":

            Code:
            public class PostalAddressDataSource extends DataSource {
                public PostalAddressDataSource(DataSource parentDS) {
            	this.setDataFormat(DSDataFormat.JSON);
                    this.setRecordXPath("/Person/Address");
                    ...
                }
            }
            I thought this would work but now I get an RPCError:

            http://.../Application/sc/IDACall

            What would cause above error?
            Last edited by farrukh_najmi; 10 Mar 2009, 06:31.

            Comment


              #7
              bump? Any updates

              Were you able to figure this out?

              Comment

              Working...
              X