Jun 15, 2011, 4:22 PM
[CLOSED] When HttpWriteProxy fails Save listener still invoked instead of SaveException listener
Hi,
I am finding is this:
This means it is hard to determine whether I am handling a save or failure condition (unless I structure the string message into a serialized JSON object with more information, but that feels like bit of a workaround).
Question 1: Is this a bug and should SaveException listener be invoked instead?
Question 2: If Save must always be invoked regardless of success or failure, can the arg also have the success property, because all I see is just the message property?
Here's a working demo (with specific steps to reproduce below it):
1) The ASPX
Question 3: (least important) Would it be possible to have a method on your Store object to setUpdateParams bit like setBaseParams?
I found that trying to dynamically update the Write params felt a bit more trickier than it needed to be: you can see in the button click handlers I had to call a method that would "cache" the simulation type in a custom save handler, then I'd also need to provide a beforeSave event handler to take that cached data and update the options accordingly.
I tried to look for some kind of method to do this and couldn't see one, though I could certainly have missed it. If not, a store.setUpdateParams() or something like that could be quite handy. (Should I put this question 3 into a separate forum post?)
I am finding is this:
- I use an HttpWriteProxy and in the ashx implementation if there is some error condition, I set the storeResponse's Success property to false
- When looking at the http requests and responses I see the correct Success (true or false) being set
- But by the time the Store listeners are invoked, it seems only the Save listener is invoked and it is only passed the message, not the success property
- The SaveException listener is not invoked
This means it is hard to determine whether I am handling a save or failure condition (unless I structure the string message into a serialized JSON object with more information, but that feels like bit of a workaround).
Question 1: Is this a bug and should SaveException listener be invoked instead?
Question 2: If Save must always be invoked regardless of success or failure, can the arg also have the success property, because all I see is just the message property?
Here's a working demo (with specific steps to reproduce below it):
1) The ASPX
<%@ Page Language="C#" %>
<!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>Store Response Tests</title>
<script type="text/javascript">
var StoreResponseTests = {
saveSuccess : function(store, object, arg) {
console.log("save succeeded", arg);
},
saveFailed : function(store, object, arg) {
console.log("save failed", arg);
},
simulationType : 'success',
beforeSave: function(store, options) {
options.params.SimulationType = StoreResponseTests.simulationType;
},
doSave: function(store, simulationType) {
StoreResponseTests.simulationType = simulationType;
store.save();
}
};
</script>
</head>
<body>
<form id="HtmlForm" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" Title="Edit stuff and then save" AutoExpandColumn="name" Height="300">
<Store>
<ext:Store ID="Store1" runat="server" ShowWarningOnFailure="false">
<Proxy>
<ext:HttpProxy Url="GetData.ashx" />
</Proxy>
<UpdateProxy>
<ext:HttpWriteProxy Method="POST" Url="UpdateData.ashx" />
</UpdateProxy>
<Reader>
<ext:JsonReader Root="Data" TotalProperty="TotalRecords">
<Fields>
<ext:RecordField Name="id" />
<ext:RecordField Name="name" />
</Fields>
</ext:JsonReader>
</Reader>
<WriteBaseParams>
<ext:Parameter Name="SimulationType" Value="success" />
</WriteBaseParams>
<Listeners>
<BeforeSave Fn="StoreResponseTests.beforeSave" />
<Save Fn="StoreResponseTests.saveSuccess" />
<SaveException Fn="StoreResponseTests.saveFailed" />
</Listeners>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ColumnID="id" Header="Id" DataIndex="id" Width="20" Sortable="true" />
<ext:Column ColumnID="name" Header="Name" DataIndex="name">
<Editor>
<ext:TextField ID="NameEditorField" runat="server" />
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="Button1" Text="Simulate Normal Save" runat="server">
<Listeners>
<Click Handler="StoreResponseTests.doSave(#{Store1}, 'success');" />
</Listeners>
</ext:Button>
<ext:Button ID="Button2" Text="Simulate Save With Errors" runat="server">
<Listeners>
<Click Handler="StoreResponseTests.doSave(#{Store1}, 'fail');" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<LoadMask ShowMask="true" />
<SaveMask ShowMask="true" />
</ext:GridPanel>
</form>
</body>
</html>
2) Dummy GetData.ashx.csusing System.Collections.Generic;
using System.Web;
namespace Ext.Net.Tests.Grid.HttpWriteProxy
{
public class GetData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
var data = new List<Dictionary<string, object>>
{
new Dictionary<string, object> { { "id", "1"}, { "name", "Name 1" } },
new Dictionary<string, object> { { "id", "2"}, { "name", "Name 2" } },
new Dictionary<string, object> { { "id", "3"}, { "name", "Name 3" } },
new Dictionary<string, object> { { "id", "4"}, { "name", "Name 4" } }
};
var plants = new Paging<Dictionary<string, object>>(data, 4);
context.Response.Write(JSON.Serialize(plants));
}
public bool IsReusable
{
get { return false; }
}
}
}
3) Dummy UpdateData.ashx.csusing System.Web;
namespace Ext.Net.Tests.Grid.HttpWriteProxy
{
public class UpdateData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
var storeResponse = new Response(true);
var simulationType = context.Request["SimulationType"];
storeResponse.Message = JSON.Serialize(simulationType);
storeResponse.Success = simulationType == "success";
storeResponse.Write();
}
public bool IsReusable
{
get { return false; }
}
}
}
To reproduce:- Edit anything in the name column
- Press the first save button to simulate no errors - with Firebug open - note the response has success in it (as expected) and the console logs out the call to the save handler (as expected)
- Edit anything in the name column again
- This time press the second save button to simulate errors - with Firebug open - note the response has success false in it (as expected) and the console logs out the call to the save handler (not expected)
Question 3: (least important) Would it be possible to have a method on your Store object to setUpdateParams bit like setBaseParams?
I found that trying to dynamically update the Write params felt a bit more trickier than it needed to be: you can see in the button click handlers I had to call a method that would "cache" the simulation type in a custom save handler, then I'd also need to provide a beforeSave event handler to take that cached data and update the options accordingly.
I tried to look for some kind of method to do this and couldn't see one, though I could certainly have missed it. If not, a store.setUpdateParams() or something like that could be quite handy. (Should I put this question 3 into a separate forum post?)
Last edited by Daniil; Jun 15, 2011 at 7:37 PM.
Reason: [CLOSED]