[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
Code:
<%@ 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
Code:
<%@ 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;
}
}
}