Announcement

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

    ListGrid Pagination with RestDataSource

    I have an issue with the ListGrid Pagination with a RestDataSource.
    Given:

    Code:
        private static final Map<String, Object> urlParams = new HashMap<>();
    
        static {
            urlParams.put("app", "catv_client");
        }
    
        private static OperationBinding createBinding(final String httpMethod, final DSOperationType operationType) {
            final DSRequest request = new DSRequest();
            request.setHttpMethod(httpMethod);
            request.setParams(urlParams);
            request.setWillHandleError(true);
    
            final OperationBinding binding = new OperationBinding();
            binding.setOperationType(operationType);
            binding.setDataProtocol(DSProtocol.POSTMESSAGE);
            binding.setRequestProperties(request);
    
            return binding;
        }
    
        public static DataSource createRest(final RestDataSource ds) {
            ds.setDataFormat(DSDataFormat.JSON);
            ds.setPrettyPrintJSON(true);
    
            final OperationBinding fetch = createBinding("GET", DSOperationType.FETCH);
            final OperationBinding add = createBinding("POST", DSOperationType.ADD);
            final OperationBinding update = createBinding("PUT", DSOperationType.UPDATE);
    
            // REMOVE PARAMS
            final OperationBinding remove = createBinding("POST", DSOperationType.REMOVE);
            String removeUrl = "/DELETE";
            if (url != null) {
                removeUrl = url.replace("?", "/DELETE?");
            }
    
            ds.setOperationBindings(fetch, add, update, remove);
            ds.setRemoveDataURL(removeUrl);
    
            return ds;
        }
    This is basically the code for making RestDataSource REST compliant. By default it doesn't use the HTTP-methods, so I had to change the operationBindings. For most of the things this works fine but for paginated listgrid requests it doesn't.

    Browsing through the form I saw a post of somebody who has overridden the transformRequest-method, so I gave it a try and I noticed that at that point the DSRequest contains all the information needed for a good pagination request (startRow, etc ...). I didn't change the return, I tried it barely used it for debugging reasons. But the thing is that all the information I have at that point it never reaches my server.

    When I look at the request that my server receives I see no parameters at all, besides the one I added myself in the createBinding() method (app=catv_client). The body is also empty, so somewhere between the transformRequest-method and the actual call all the information is lost.

    I think the origin of my problems is the fact that I manually set the OperationBindings.

    #2
    Your immediate problem is most likely that you override transformRequest but either don't call Super() or modify the original request passed into that method rather than the one returned by Super. The bulk of the RestDataSource logic is in transformRequest, so if you skip it, you cripple the class.

    Your bigger problem is that by trying to use different HTTP verbs for each operationType, you cripple the RestDataSource's ability to use queuing (combining multiple DSRequests into a single HTTP request), which in turn cripples many key features of SmartGWT's advanced UI components.

    To understand this more fully, read the QuickStart Guide sections on queuing and then read the RestDataSource docs on queuing. What you almost certainly want to do it delete all your customization code and use the RestDataSource in its default mode, which is the why it is the default mode :)

    Comment

    Working...
    X