PDA

View Full Version : NullReferenceException when using ServerMapping



nextSTEP
Feb 09, 2011, 9:52 AM
Hi,

I'm using ServerMapping on RecordFields for complex objects. I specified a property that doesn't exist. This threw a NullReferenceException when the data was being bound.
It took me a while to check why there is the exception. I think it should throw a more detailled exception that tells me that the property does not exist.

public abstract partial class StoreDataBound
2290

Daniil
Feb 17, 2011, 8:39 AM
Hi,

Please clarify how we can reproduce it?

I set non-existing property for ServerMapping but the issue doesn't appear.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
class Test
{
public string Test1 { get; set; }
public string Test2 { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new Test
{
Test1 = "test11",
Test2 = "test12"
},
};
store.DataBind();
}
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.Net Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="test11" ServerMapping="Test1" />
<ext:RecordField Name="test2" ServerMapping="notExists" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Header="Test1" DataIndex="test1" />
<ext:Column Header="Test2" DataIndex="test2" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>

nextSTEP
Feb 17, 2011, 8:46 AM
Try specifying a nested property:


class Test
{
public Test2 Test1 { get; set; }
public string Test2 { get; set; }
}

class Test2
{
public string NestedTest1 { get; set; }
}


<ext:RecordField Name="test2" ServerMapping="Test1.NestedTest1" /> // works
<ext:RecordField Name="test2" ServerMapping="Test1.notExists" /> // Exception

Daniil
Feb 17, 2011, 8:55 AM
Thank you, now I reproduced.

I will discuss this issue with Dev team.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
class Test
{
public Test2 Test1 { get; set; }
public string Test2 { get; set; }
}

class Test2
{
public string NestedTest1 { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new Test
{
Test1 = new Test2()
{
NestedTest1 = "test11"
},
Test2 = "test12"
},
};
store.DataBind();
}
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.Net Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="test1" ServerMapping="Test1.NestedTest1" />
<ext:RecordField Name="test2" ServerMapping="Test1.notExists" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Header="Test1" DataIndex="test1" />
<ext:Column Header="Test2" DataIndex="test2" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>

nextSTEP
Feb 17, 2011, 8:59 AM
I love it to enhance things :)

Daniil
May 20, 2011, 1:20 PM
Hi @nextSTEP,

The related feature ticket:
https://extnet.lighthouseapp.com/projects/50558-features/tickets/91

This has been implemented, revision #3570.

It will be also available in RC2.

Thanks for pointing it out.