Announcement

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

    invalidateCache is ignored by RestDataSource

    Hello,

    It looks like RestDataSource is completely ignoring invalidateCache flag. I used the test project from wiki https://isomorphic.atlassian.net/wik...?pageId=524942 with invalidateCache flag added to the add request, see the attachment. Once user hits Add button a new record gets added as expected, but since invalidateCache is set to true in the response, a new fetch should be issued by the grid. The grid is not refreshing though. Both 3.1 and 4.0d behave the same.
    RestDataSource documentation mentions that "The request and response formats used by the RestDataSource allow for many of the available features of Smart GWT's databinding system to be used, including data paging, searching & sorting, long transactions, automatic cache sync, relogin and queuing." Does it imply that invalidateCache should be supported?
    Attached Files

    #2
    Right now, there's no format defined for passing this flag. You can add a transformResponse override, **call super**, then check for the flag in the raw XML ("data" parameter) yourself, and apply it to the dsResponse.

    Comment


      #3
      Thank you very much. That works just fine. Is there a better way to look at the response and set invalidateCache flag? RestHandler servlet adds it to the response body, not the data, so this solution is not working with the packaged RestHandler servlet unfortunately.

      Comment


        #4
        Sorry, it's unclear what you mean. The invalidateCache flag would not be expected to be in the dsResponse.data. It is a metadata flag, like status.

        Comment


          #5
          Here's an example of a response generated by SmartGWT RestHandler servlet that includes invalidateCache flag:
          Code:
          <SCRIPT>//'"]]>>isc_JSONResponseStart>>{"response":{"data":{"BATCH_FK":23},"invalidateCache":true,"isDSResponse":true,"operationType":"update","queueStatus":0,"status":0}}//isc_JSONResponseEnd
          It's definitely a flag, not a part of data. I was wondering if there's a better way to modify RestDataSource so it would work with both RestHandler servlet and the custom JSON server?

          Comment


            #6
            Read closely - the advice in post #2 is to look at the data *parameter* (to transformResponse), and *not* dsResponse.data.

            The data *parameter* is an XML or JSON object holding the entire server response.

            Comment


              #7
              Solved!

              Thank you for the help. It works now! Here's the full implementation in case someone needs it:
              Code:
              @Override
              protected void transformResponse(DSResponse response, DSRequest request, Object data) {
              	super.transformResponse(response, request, data);
              		
              	Map<String, Object> dataMap = JSOHelper.convertToMap((JavaScriptObject) data);
              	if (dataMap != null && dataMap.get("response") != null) {
              	Map<String, Object> objMap = (Map<String, Object>) dataMap.get("response");
              	Boolean invalidateCache = (Boolean) objMap.get("invalidateCache");
              	response.setInvalidateCache(invalidateCache);
              	}
              }

              Comment

              Working...
              X