[CLOSED] ModelField useNull when populating from HTTP handler

  1. #1

    [CLOSED] ModelField useNull when populating from HTTP handler

    The sample below shows that when I retrieve the TitleId, for ProductID = 3, from a store populated locally with the useNull="true" on the ModelField the value of the attribute in the data and raw objects of the store is NULL. When I retrieve it via an HTTP handler the data object of the store has 0, but the raw object has NULL.
    Local Store (Data) - null
    Local Store (Raw) - null
    HTTP Store (Data) - 0
    HTTP Store (Raw) - null

    Am I doing something incorrectly in the JSON?

    StoreNullInt01.aspx
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                int? a = 11;
                int? b = 22;
                int? c = null;
                int? d = null;
    
                LocalStore.DataSource = new Object[]
                {
                    new  {ProductID = 1, TitleId = a},
                    new  {ProductID = 2, TitleId = b},
                    new  {ProductID = 3, TitleId = c},
                    new  {ProductID = d, TitleId = 44}
                };
    
                HttpStore.Reload();
            }
        }
    </script>
    <head runat="server">
        <title>Store - NULL Integer</title>
        <style type="text/css">
        </style>
        <script type="text/javascript">
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Container runat="server">
            <HtmlBin>
                <ext:Store ID="HttpStore" runat="server" ClientIDMode="Static">
                    <Proxy>
                        <ext:AjaxProxy Url="StoreNullInt01.ashx?mode=products">
                            <Reader>
                                <ext:JsonReader Root="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="ProductID" Type="Int" />
                                <ext:ModelField Name="TitleId" Type="Int" UseNull="true" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
                <ext:Store ID="LocalStore" runat="server" ClientIDMode="Static">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="ProductID" Type="Int" />
                                <ext:ModelField Name="TitleId" Type="Int" UseNull="true" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
    
                <script type="text/javascript">
                    function showData() {
                        var httpRecord = App.HttpStore.findRecord('ProductID', 3, 0, false, false, true);
                        var localRecord = App.LocalStore.findRecord('ProductID', 3, 0, false, false, true);
                        Ext.Msg.alert('Data ...', 'Local Store (Data) - ' + localRecord.data.TitleId + '<br/>' +
                                                  'Local Store (Raw) - ' + localRecord.raw.TitleId + '<br/>' +
                                                  'HTTP Store  (Data) - ' + httpRecord.data.TitleId  + '<br/>' +
                                                  'HTTP Store  (Raw) - ' + httpRecord.raw.TitleId);
                    }
                </script>
            </HtmlBin>
        </ext:Container>
        <ext:Button runat="server" Text="Show Me" OnClientClick="showData();" />
    </body>
    </html>
    StoreNullInt01.ashx
    <%@ WebHandler Language="C#" Class="StoreNullInt01" %>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    using Ext.Net;
    
    public class StoreNullInt01 : IHttpHandler
    {
    
        public void ProcessRequest(HttpContext context)
        {
            string mode = context.Request["mode"];
    
            context.Response.ContentType = "text/javascript";
            List<object> data = new List<object>();
            MetaConfig metaData = new MetaConfig();
    
            int? a = 11;
            int? b = 22;
            int? c = null;
            int? d = null;
    
            data.Add(new { ProductID = 1, TitleId = a });
            data.Add(new { ProductID = 2, TitleId = b });
            data.Add(new { ProductID = 3, TitleId = c });
            data.Add(new { ProductID = d, TitleId = 44 });
    
            metaData = MetaConfig.From(data);
            metaData.IDProperty = "ProductID";
            metaData.Root = "data";
    
            new StoreResponseData
            {
                Data = JSON.Serialize(data),
                MetaData = metaData
            }.Return();
        }
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    Last edited by Daniil; May 12, 2014 at 5:18 PM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    I think this overrides/erases the Store's Model settings.
    MetaData = metaData // in StoreResponseData
  3. #3
    That was it. I copied code 8 months ago when I first started the http handlers and obviously did not understand all the details. Now I do.

    Please close the thread.

Similar Threads

  1. [CLOSED] how to get modelfield from RowSelectionModel?
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 10, 2014, 6:08 AM
  2. How to get ModelField Value in ComboBox
    By coder in forum 2.x Help
    Replies: 1
    Last Post: Nov 24, 2013, 2:51 AM
  3. [CLOSED] datetime format in ModelField?
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 18, 2013, 12:20 PM
  4. [CLOSED] Mapping on ModelField
    By ptrourke in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 18, 2013, 12:45 AM
  5. ext:ModelField Mapping attribute not working
    By jbarbeau in forum 2.x Help
    Replies: 5
    Last Post: Jan 14, 2013, 10:01 AM

Posting Permissions