1. #151
    Ext JS Premium Member
    Join Date
    Oct 2009
    Location
    Hamilton ON Canada
    Posts
    25
    Vote Rating
    0
    fargs is on a distinguished road

      0  

    Default 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

    Code:
    Ext.Direct.on('exception', function(e) {
        Ext.Msg.show({
               title:'Woops!',
               msg: e.message,
               buttons: Ext.Msg.OK,
               icon: Ext.MessageBox.ERROR
        });
    });
    My form submit code is:

    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 ...' });
    Scenario:
    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.

    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);
            }
        },
    Solution:
    OPEN FOR DISCUSSION!


    Thanks and great work!

  2. #152
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    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!

  3. #153
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    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 )

    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);
            }
    Changes to only return methods that return typeof(DirectResult)
    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
    Marco
    Last edited by mdissel; 18 Jan 2010 at 7:03 AM. Reason: added my changes

  4. #154
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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.

  5. #155
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    Quote Originally Posted by elishnevsky View Post
    fargs
    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.
    If you're pointing to
    Code:
    this.ActionInvoker = new DirectMethodInvoker();
    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..

    something like:
    Controller controller = _factory.CreateController(requestContext, request.Action) as Controller;
    ....
    controller.ActionInvoker = new DirectMethodInvoker();
    (controller as IController).Execute(requestContext);

  6. #156
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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.

  7. #157
    Ext JS Premium Member
    Join Date
    Oct 2009
    Location
    Hamilton ON Canada
    Posts
    25
    Vote Rating
    0
    fargs is on a distinguished road

      0  

    Default


    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.

  8. #158
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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.

  9. #159
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Uploaded Ext.Direct.Mvc v0.8.3.

    See the first post of this thread for the download link.

    Changes:
    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.
    This means two things:
    1. 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.
    2. 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.

  10. #160
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    Quote Originally Posted by elishnevsky View Post
    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.
    Correct. We should start a new thread discussion the clientside events in this particular situation.