Announcement

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

    How to do server validation and return data as well?

    I'm trying to figure out how to use one call to the server to validate a field in a ListGrid and return values that can then be used to populate other fields in that grid record. I don't want to make two server calls since the validation call already has to access all of the same data I need to return.

    I've tried adding a ChangedHandler to the field and an EditorExitHandler and making the call to the server within those. But I can't seem to figure out how to recreate the behavior of a normal validator (flagging the field as an error, resetting the value when escape key is pressed, etc.).

    It seems like there must be a better way. Any advice?

    #2
    Why are you trying to "recreate" the behavior of a normal validator - why not just use a validator?

    Trying to add errors externally has very messy lifecycle issues (when the error is cleared, etc). The cleanest approach is to provide an actual validator, so that the ListGrid can re-run the validator to see if there is still an error.

    Comment


      #3
      I can't see any way for the server side validator to return data?

      Comment


        #4
        What is this additional data? Is it related to validation? If not, just trigger it separately. If it is related to validation, you could turn off automatic validation and trigger it manually, using queuing to do this second, related operation in the same HTTP request.

        Comment


          #5
          The validation is simply making sure that the field value entered can be used to locate a record in a table (it's a little more complicated than that but that is essentially what's happening). If the record exists, and meets some other criteria, validation passes and I can send back selected fields from that record to the client. Otherwise validation fails.

          So the validator has already read the database and validated the record, but can't send it back to the client.

          I'm not sure I understand how to "turn off automatic validation and trigger it manually, using queuing to do this second, related operation in the same HTTP request." but it sounds complicated.

          Comment


            #6
            I've tried a variety of things now and can't seem to find the right combination. Can you please describe in more detail what you mean by "turn off automatic validation and trigger it manually, using queuing to do this second, related operation in the same HTTP request"?

            I would like to do everything in one operation if at all possible. The server has to do some non-trivial database access to do the validation. If the result is success, the server already has assembled the data the client needs, which is why I was hoping to be able to somehow send it back in the validator's response.

            It sounds like the method you're suggesting would still require two executions of the server code, but at least would make both executions run in one HTTP request. Could you elaborate on how to do that or provide an example?

            The basic requirement is that when the user tabs out of a file in the ListGrid a call is made to the server to validate the new field value and if validation passes, update some other fields in the record being edited with default values retrieved from the server.

            Comment


              #7
              It means using listGrid.neverValidate:true and then making calls to listGrid.validateRow() et al to trigger validation manually. Since you're in control of when validation occurs, you can use RPCManager.startQueue() to combine any request automatically issued by validation with an request of your own.

              You could then take results of the expensive operation done by the validator are store it on the HTTPServletRequest or RPCManager, so you could pick them up from a DMI.

              However another alternative that might be simpler is representing this as an update operation on the row. After all, an update run validation and is allowed to return cache sync data that is automatically applied to the row, which is what you seem to want to do.

              Comment


                #8
                Thanks. The faux update idea sounds like the simpler of the two. I'll give that a try.

                Comment

                Working...
                X