Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DynamicForm.saveData: callback not called when status < 0

    I have a DynamicForm but when I save it and the save fails (response with status < 0), the callback is not called,
    I thought this would be fixed with setWillHandleError but it is not (this setWillHandleError fixed the same problem on my ListGrid)

    See below for a piece of the code and the DSResponse

    Code:
    DSRequest requestProperties = new DSRequest();
    requestProperties.setWillHandleError(true);
    editForm.saveData(new DSCallback() {
      public void execute(DSResponse response, Object rawData,
        DSRequest request) {
        if (response.getStatus() < 0) {
          SC.warn((String)rawData);
        }
     }, requestProperties);
    DSResponse:

    Code:
    [
        {
            errors:[
                {
                    errorNotAllowed:{errorMessage:"You are not authorized"}
                }
            ],
            isDSResponse:true,
            invalidateCache:false,
            status:-4,
            data:"You are not authorized"
        }
    ]

    #2
    It seems likely you are using a validation error for something which is really not a validation error (it does indicate a failure on a particular field). Instead, you want to flag a general error (-1) and use system-wide error handling (see RPCManager handleError).

    Comment


      #3
      Thanks, that was indeed the problem,
      it was a validation error on a particular field but I just had to change the error key to the name of that field to show the error on the form.

      Comment


        #4
        I ran into this issue today, except mine really is a validation error. I wanted to do some conditional UI stuff in addition to the validation specific stuff, after the validation error. Is there a place to hook into to accomplish something like this? Am I understanding correctly that the saveData() callback only gets called on a successful save?

        Cheers,

        Alex

        Comment


          #5
          I just found out the same thing.

          Here's the scenario:
          * a user changes a field and a server vm.saveData(callback, prop) operation is called
          * on another field, there is a server validator
          * the validators are checked during the saveData operation (OK)
          * the saveData operation is stopped and the DSResponse contains status -4 because of validation error (this is OK)
          but the callback passed to saveData is never called.
          Instead, the HiddenValidationErrorsHandler 'catches' the validation error.


          My callback is programmed already to catch good and bad responses and act accordingly, but in this case, it's not doing anything.

          I'm wondering if there is an option to change this behavior and make the callback be called as well when there is a validation error as in this situation. - in fact, this should be a system-wide setting for us. The callback can then be enhanced to hook into the system which transforms the dsresponse into an ErrorMap, just like HiddenValidationErrorsEvent.getErrors() and then act accordingly by custom behavior specified in the callback handler (which can then be made specific).

          E.g. a setWillHandleValidationError option.


          @others in thread: you can do a component.addHiddenValidationErrorsHandler to catch the validation error.

          Comment


            #6
            On reflection we agree that the callback should be fired if 'willHandleError' is specified on the DSRequest for any server errors, including validation errors.

            We've made this change and it will show up in nightlies from this point forward.

            EDIT: Also - just to reiterate levi's point - addHiddenValidationErrorHandler() exists at the ValuesManager level so you can add a custom handler for hidden validation errors there.

            Comment


              #7
              Thanks, verified in 14/05/2011 build.

              However, in case of the validation error occurring because of a server call, shouldn't then the validation error be exclusively handled via that callback?

              Now, the HiddenValidationErrorsHandler AND the callback are both fired when the response code is RPCResponse.STATUS_VALIDATION_ERROR.


              Furthermore, the field responsible for the validation error is actually not hidden (as per javadoc comment on the addHiddenValidationErrorHandler).
              In this case, the key of the error coming from HiddenValidationErrorsEvent.getErrors() is "path1[0]/reference/errorMessage".
              Where 'reference' is the name of the field (which is visible and part of a form which is part of the valuesmanager)
              Maybe this should be "path1[0]/reference" to not get the HiddenValidationErrorHandler think this is a hidden field?
              (related info also on issue 2421).

              Comment


                #8
                Are you saying that all errors on your fields are being reported as hidden validation errors when the fields are in fact present? Please show a standalone test case.

                Comment


                  #9
                  Yes, field "reference" is really on the UI.
                  No, other errors are not reported as hidden validator errors.

                  The field is created via a field having dataPath="/path1/reference"
                  The DS validator definition on the base field:
                  Code:
                  <validator stopIfFalse="true" stopOnError="false" type="serverCustom" validateOnChange="true">
                  <serverCondition><![CDATA[$util.contains($value.text, 'test')]]></serverCondition>
                  <errorMessage>problem: The reference must contain the text string 'test'.</errorMessage>
                  </validator>

                  This is the DSResponse:
                  Code:
                  [
                      {
                          queueStatus:-1, 
                          errors:[
                              {
                                  path1:[
                                      {
                                          reference:{
                                              errorMessage:"problem: The reference must contain the text string 'test'."
                                          }
                                      }
                                  ]
                              }
                          ], 
                          isDSResponse:true, 
                          invalidateCache:false, 
                          status:-4, 
                          data:null
                      }
                  ]
                  In my valuesManager, I have a logger on the hidden validation error which outputs the errormap from the hidden validation event (key => value):
                  Code:
                  vm.addHiddenValidationErrorsHandler errors: 1 detected!
                  Map contains 1 keys and 1 values:
                  path1[0]/reference/errorMessage => problem: The reference must contain the text string 'test'.
                  I don't know if it's correct that the key shows the datapath?


                  From my callback, I check on the status validation error, and this is now also hit: A validation error has occurred. (after the hiddenValidator code is triggered).


                  I don't think all my validation errors are reported in thie hiddenValidatorHandler - in fact, I'll gamble here: the problem is only with serverCustom validators.

                  This is my only serverCustom validator in place, so I can't test this assumption on others at the moment.
                  ClientOnly validator errors are not caught via the hiddenValidatorHandler.


                  thanks,

                  Comment


                    #10
                    Hello, I'm using SmartGWT 2.5, and apparently I'm getting the opposite expected behavior from the DSRequest.willHandleError attribute.

                    My DataSource is created with:

                    [CODE]
                    dataSource = new RestDataSource() {
                    @Override
                    protected Object transformRequest(
                    DSRequest request )
                    {
                    // TODO: Nossa callback não recebe mensagens com status < 0.
                    // Aparentemente isso foi corrigido no SmartGWT 2.5
                    // Referência:
                    // http://forums.smartclient.com/showthread.php?t=9842
                    request.setWillHandleError( false );
                    return super.transformRequest( request );
                    }
                    };

                    Comment


                      #11
                      Hello, I'm using SmartGWT 2.5, and apparently I'm getting the opposite expected behavior from the DSRequest.willHandleError attribute.

                      My DataSource is created with:

                      Code:
                      dataSource = new RestDataSource() {
                         @Override
                         protected Object transformRequest(DSRequest request )
                         {
                            request.setWillHandleError( false );
                            return super.transformRequest( request );
                         }
                      };
                      And in my DynamicForm, I have something like:

                      Code:
                      this.callback = new DSCallback() {
                         @Override
                         public void execute(
                            DSResponse response,
                            Object rawData,
                            DSRequest request )
                         {
                            processResponse( response );
                          }
                      };
                      and I save the data in the form with:

                      Code:
                      form.saveData( callback );
                      The thing is: when the response has status < 0, if I set willHandleError to false, my callback is called. If I set it to true, the callback is not called anymore.

                      Shouldn't it be the other way around? Or maybe I'm doing something wrong?

                      Thank's a lot!

                      Best,
                      Thiago
                      Last edited by tcoraini; 2 Sep 2011, 10:36.

                      Comment

                      Working...
                      X