-
17 Jan 2010 9:49 AM #151
Issue with action option WaitMsg and Direct Exception Handler
Issue with action option WaitMsg and Direct Exception Handler
Hi,
I have a form that causes a server side exception. I have setup the
My form submit code is:Code:Ext.Direct.on('exception', function(e) { Ext.Msg.show({ title:'Woops!', msg: e.message, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR }); });
Scenario:Code:myform.getForm().submit({success: function(form, action) { store.reload(); Ext.example.msg(action.result.msg); }, failure: actionFailedHandler, reset: true, waitTitle: 'Saving ...', waitMsg:'Please wait ...' });
When a server side exception occurs, I would like my Direct handler to display the message box with the exception details.
Problem:
When an exception occurs, the message box shows for a second and then disappears.
Root Cause:
The afterAction function in ext-all-debug.js is executed after the Direct exception handler. In this code, it checks the action options to see if the waitmsg has been set and hides any message box if it is. So, the message box that I set in the direct handler is being removed.
Solution:Code:afterAction : function(action, success){ this.activeAction = null; var o = action.options; if(o.waitMsg){ if(this.waitMsgTarget === true){ this.el.unmask(); }else if(this.waitMsgTarget){ this.waitMsgTarget.unmask(); }else{ Ext.MessageBox.updateProgress(1); Ext.MessageBox.hide(); } } if(success){ if(o.reset){ this.reset(); } Ext.callback(o.success, o.scope, [this, action]); this.fireEvent('actioncomplete', this, action); }else{ Ext.callback(o.failure, o.scope, [this, action]); this.fireEvent('actionfailed', this, action); } },
OPEN FOR DISCUSSION!
Thanks and great work!
-
18 Jan 2010 2:17 AM #152
Is it an idea to setup a central SVN (for example on code.google.com) to host this project?
This will allow more people to help to make this a perfect asp.net mvc solution for extjs!
-
18 Jan 2010 6:55 AM #153
Why is it required to inherit from DirectController?
I opt for :
- using the DirectIgnore at class level to skip exporting actions from the controller. (or maybe check for the return type of the action (equal to DirectResult )
Changes to only return methods that return typeof(DirectResult)Code:internal static bool IsDirectAction(this Type type) { bool isDirectController = type.IsSubclassOf(typeof(DirectController)); bool ignore = (!type.IsAbstract && !type.IsSubclassOf(typeof(System.Web.Mvc.Controller))) || type.HasAttribute<DirectIgnoreAttribute>(); return (isDirectController || !ignore); }
Code:internal static bool IsDirectMethod(this MethodInfo method) { // Any controller action is a Direct method unless marked with DirectIgnoreAttribute bool returnsActionResult = (method.ReturnType == typeof(DirectResult) || method.ReturnType.IsSubclassOf(typeof(DirectResult))); bool ignore = method.HasAttribute<DirectIgnoreAttribute>(); return (returnsActionResult && !ignore); }
- Implement the Direct helper function as extensions function on the System.Web.Mvc.Controller class.
Thanks
MarcoLast edited by mdissel; 18 Jan 2010 at 7:03 AM. Reason: added my changes
-
18 Jan 2010 7:08 AM #154
fargs
It is not related to Ext.Direct. It is the behaviour of Ext.MessageBox class and should not be discussed in this thread.
mdissel
I will try to move the source to Google Code sometimes this week. I have already created the project there, just never had time to finish it.
DirectController class does not only have helper methods. It also contain an override for ExecuteCore method, which is crucial in my implementation of Ext.Direct for MVC. It is the main reason for DirectController class to exist.Eugene
Ext.Direct for ASP.NET MVC
-
18 Jan 2010 7:22 AM #155
If you're pointing to
i think this could also be configured from the DirectProvider in the ExecuteRequest (by assuming the controller is based on Controller (instead of IController).. for TDD this is not so nice, but maybe there's another way to configure a different ActionInvoker..Code:this.ActionInvoker = new DirectMethodInvoker();
something like:
Controller controller = _factory.CreateController(requestContext, request.Action) as Controller;
....
controller.ActionInvoker = new DirectMethodInvoker();
(controller as IController).Execute(requestContext);
-
18 Jan 2010 8:05 AM #156
I think you are correct, thanks! I will make these changes, bump the version number and upload the new version in the next couple of days. Will also try to upload the source to Google Code.
Eugene
Ext.Direct for ASP.NET MVC
-
18 Jan 2010 1:49 PM #157
Hi Eugene,
The Ext.Messagebox.hide() is there to remove the progress box when the waitMsg is set on any action, so the message box is doing what I would expect.
I think the issue is that the exception is being handled and the code continues to execute the afterAction events. The failure callback in the action can be used (which executes last) but the direct exception handler has the data I want to display. The info passed to the failure callback is limited.
I have not dug into the inner workings of Direct MVC but would it be possible to have the Direct exception handler fire after all ext action events have fired?
I currently removed the waitMsg option on my action submit calls because if I use them the Direct Handler does not display the message box.
Thanks for you help.
-
18 Jan 2010 8:22 PM #158
fargs
What you are talking about is related solely to client-side part of Ext JS Framework and has absolutely nothing to do with server-side implementation of Ext.Direct. I don't have control on the server over the order in which the events are fired on the client.Eugene
Ext.Direct for ASP.NET MVC
-
18 Jan 2010 8:39 PM #159
Uploaded Ext.Direct.Mvc v0.8.3.
See the first post of this thread for the download link.
Changes:This means two things:Code:* Removed: DirectController class due to lack of necessity. Any controller is considered a Direct controller unless marked with DirectIgnoreAttribute which is extremely recommended. * Changed: Helper methods that were in DirectController are now implemented as extension methods of Controller class, so you must reference Ext.Direct.Mvc in your controller and call the helper methods with 'this' keyword.
- Any controller that is not intended to be used by Ext.Direct should be marked with DirectIgnore attribute. Although not required, it is highly recommended to do so, so that Ext.Direct.Mvc can completely ignore these controllers and actions they contain.
- Helper methods, such as Direct() and DirectForm() must be called with this keyword - this.Direct(...); or this.DirectForm(...); - and Ext.Direct.Mvc must be referenced with using directive at the top of your controller class.
Eugene
Ext.Direct for ASP.NET MVC
-
19 Jan 2010 2:46 AM #160


Reply With Quote