[CLOSED] Data binding to NetTiers data entity objects

  1. #1

    [CLOSED] Data binding to NetTiers data entity objects

    Hi,

    I'm trying to bind a GridPanel to a list of NetTiers entity objects deserialized as an array. The GridPanel store gets bound partially - it does have the correct count of rows but the content is not bound properly and the fields remain empty. I examined the example at https://examples1.ext.net/#/GridPane...Field_Mapping/ to get started and played around Mapping property and Column Renderer handler a bit with no results. I think I must be missing the way to drill down the NetTiers object graph to do the binding correctly. Please advise. I realize you may require more information about the structure of the NetTiers objects so let me know. It's pretty linear and doesn't contain other custom objects.

    Thanks,

    Vadym

        <script type="text/javascript">
            var idRenderer = function (value) {
                //alert(value);
                if (!Ext.isEmpty(value)) {
                    return value.ID;
                }
    
                return value;
            };
    
            var someNameRenderer = function (value) {
                //alert(value);
                if (!Ext.isEmpty(value)) {
                    return value.SomeName;
                }
    
                return value;
            };
        </script>
        <ext:Store ID="Store1" runat="server" SerializationMode="Complex">
            <Reader>
                <ext:JsonReader IDProperty="ID">
                    <Fields>
                        <ext:RecordField Name="ID" Type="Int" />
                        <ext:RecordField Name="SomeName" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:GridPanel ID="GridPanel1" EnableViewState="true" AutoHeight="true" runat="server"
            StoreID="Store1">
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="ID" DataIndex="ID">
                        <Renderer Fn="idRenderer" />
                    </ext:Column>
                    <ext:Column Header="SomeName" DataIndex="SomeName">
                        <Renderer Fn="someNameRenderer" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    // Initialize the WCF service proxy object
                    ServiceClient client = new ServiceClient();
                    MyObject_GetAllRequest req = new MyObject_GetAllRequest();
                    MyObject_GetAllResponse resp = client.MyObject_GetAll(req);
                    MyObject[] myObjects = resp.MyObject_GetAllResult;
    
                    this.Store1.DataSource = myObjects;
                    this.Store1.DataBind();
    
                    // The actual properties of the MyObject class are encapsulated
                    // inside the "entityData" object - probably, part of the inner workings of NetTiers ORM
                    // So, to get a hold of the SomeName field, I'd need to do something like:
                    MyObject test=myObjects[0];
                    String someName=test.entityData.SomeName;
                }
            }
    Last edited by Daniil; Apr 09, 2012 at 4:08 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please call
    X.Msg.Alert("", JSON.Serialize(myObjects)).Show();
    within the Page_Load and post here the result.

    We will look how your data is serialized and could suggest a respective Reader configuration.
  3. #3
    Hi Daniil,

    Here's the serialized markup of the myObjects array:

    [
    	{
    		"_originalData":
    			{"EntityState":"Unchanged","MyTable1Collection":[],"MyTable2Collection":[],"MyTable3Collection":[],"Id":1,"SomeName":"Test 1","OriginalId":1,"MyTable4Collection":[],"MyTable5Collection":[],"SomeDate":"2012-04-04T22:04:04.890","SomeStatus":1,"MyTable6Collection":[]},
    		"entityData":
    			{"EntityState":"Unchanged","MyTable1Collection":[],"MyTable2Collection":[],"MyTable3Collection":[],"Id":1,"SomeName":"Test 1","OriginalId":1,"MyTable4Collection":[],"MyTable5Collection":[],"SomeDate":"2012-04-04T22:04:04.890","SomeStatus":1,"MyTable6Collection":[]},
    		"entityHashCode":null
    	}
    ]
    I limited the call to retrieve one record for simplicity. The structure of my MyObject entity is as follows:
    Id int PK,
    SomeName string,
    SomeDate DateTime,
    SomeStatus int
    MyTable1 through MyTable6 are the entities where the Id field from the MyObject entity occurs as Foreign Key. Note that the corresponding arrays are empty as DeepLoad wasn't invoked to query the relationship dependencies. For the sake of this exercise, I'm trying to bind a GridPanel to myObjects array to display all the primitive fields of the MyObject entity only. If that works, I will need to see if other entity objects deeper down the hierarchy tree can be bound to.

    Thanks,

    Vadym
  4. #4
    At the first of all, please note that you can use ServerMapping with
    SerializationMode="Complex"
    A data is not parsed on server at all with that mode, it's just serialized.

    The following Store should work for you.

    Example
    <ext:Store runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="_originalData_Id" ServerMapping="_originalData.Id" />
                    <ext:RecordField Name="_originalData_SomeName" ServerMapping="_originalData.SomeName" />
                    ...
                    <ext:RecordField Name="entityData_Id" ServerMapping="entityData.Id" />
                    <ext:RecordField Name="entityData_SomeName" ServerMapping="entityData.SomeName" />
                    ...
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    For the complex properties you can set up
    IsComplex="true"
    for a respective RecordField.
  5. #5
    Thanks Daniil! That worked great for atomic fields. I'm trying to data bind to a collection object down the hierarchy tree like below:

        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Id" ServerMapping="entityData.Id" />
                        <ext:RecordField Name="SomeName" ServerMapping="entityData.SomeName" />
                        <ext:RecordField Name="MyTable1Field" ServerMapping="entityData.MyTable1Collection[0].entityData.MyTable1Field" IsComplex="true" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
    I'm getting a runtime exception "Mapped property 'MyTable1Collection[0]' doesn't exist". In the debug mode in code behind, I'm able to view the value of
    myObjects[0].entityData.MyTable1Collection[0].entityData.MyTable1Field
    myObjects array's length is 1, MyTable1Collection array contains one element.

    Thanks,

    Vadym
  6. #6
    Unfortunately, indexer properties are not supported by server mapping
  7. #7
    ServerMapping doesn't support indexing.

    You can use
    <ext:RecordField Name="MyTable1Collection" ServerMapping="entityData.MyTable1Collection" IsComplex="true" />
    Then a record MyTable1Collection field value will be an array on client and you can manage it client side.
  8. #8
    Thanks again for some great suggestions! I tried the code below and it worked to prove the concept. You can mark this question as resolved.

        <script type="text/javascript">
            var myTable1FieldRenderer = function (value) {
                if (!Ext.isEmpty(value)) {
                    return value[0].entityData.MyTable1Field;
                }
    
                return value;
            };
        </script>
    
    <ext:Store ID="Store1" runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="Id" ServerMapping="entityData.Id" />
                    <ext:RecordField Name="SomeName" ServerMapping="entityData.SomeName" />
                    <ext:RecordField Name="MyTable1Field" ServerMapping="entityData.MyTable1Collection" IsComplex="true" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    
    <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1">
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Id" DataIndex="Id" />
                    <ext:Column Header="SomeName" DataIndex="SomeName" />
                    <ext:Column Header="MyTable1Field" DataIndex="MyTable1Field">
                        <Renderer Fn="myTable1FieldRenderer" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
    </ext:GridPanel>
    Thanks,

    Vadym

Similar Threads

  1. ComboBox data binding
    By AlexMaslakov in forum 1.x Help
    Replies: 3
    Last Post: Jun 13, 2013, 9:04 AM
  2. Data not binding into ComboBox
    By nagesh in forum 1.x Help
    Replies: 5
    Last Post: Jul 12, 2012, 2:35 PM
  3. Replies: 0
    Last Post: Oct 23, 2011, 5:37 PM
  4. Store Data is not binding
    By Rahul in forum 1.x Help
    Replies: 7
    Last Post: Jul 27, 2011, 10:31 AM
  5. Data Binding
    By Deepak in forum 1.x Help
    Replies: 3
    Last Post: Nov 04, 2010, 10:27 AM

Tags for this Thread

Posting Permissions