Hi,
I tried to modify the GwtRpc version of this into something that should work with RequestFactory. Just as a test I am displaying it in a ListGrid.
I have gotten as far as it making a request to my server, but there are two problems:
1) Why does it make the request TWICE?
2) ... with the same ID?
Code:
00:37:57.596 [INFO] Transforming a request 00:37:57.606 [INFO] Issue fetch request customerDataSource$6270 00:37:57.696 [INFO] Transforming a request 00:37:57.706 [INFO] Issue fetch request customerDataSource$6270 00:37:57.815 [INFO] Module admin has been loaded 00:37:57.987 [INFO] Creating a record for customer 1 00:37:57.993 [INFO] Creating a record for customer 2 00:37:57.997 [INFO] Creating a record for customer 3 00:37:57.999 [INFO] Creating a record for customer 4 00:37:58.002 [INFO] Returning 4 records 00:37:58.006 [INFO] Processing request customerDataSource$6270 00:37:58.009 [ERROR] 13:25:00.066:WARN:DataSource:customerDataSource:DataSource.processResponse(): Unable to find request corresponding to ID customerDataSource$6270, taking no action. 00:37:58.065 [INFO] Creating a record for customer 1 00:37:58.069 [INFO] Creating a record for customer 2 00:37:58.074 [INFO] Creating a record for customer 3 00:37:58.075 [INFO] Creating a record for customer 4 00:37:58.077 [INFO] Returning 4 records 00:37:58.079 [INFO] Processing request customerDataSource$6270 00:37:58.082 [ERROR] 13:25:00.139:WARN:DataSource:customerDataSource:DataSource.processResponse(): Unable to find request corresponding to ID customerDataSource$6270, taking no action.
Code:
@Override protected Object transformRequest( DSRequest request ) { GWT.log( "Transforming a request" ); String requestId = request.getRequestId(); DSResponse response = new DSResponse(); response.setAttribute( "clientContext", request.getAttributeAsObject( "clientContext" ) ); // Assume success response.setStatus( 0 ); switch ( request.getOperationType() ) { case FETCH: executeFetch( requestId, request, response ); break; case ADD: executeAdd( requestId, request, response ); break; case UPDATE: executeUpdate( requestId, request, response ); break; case REMOVE: executeRemove( requestId, request, response ); break; default: // Operation not implemented. break; } return request.getData(); }
Code:
private void executeFetch( final String requestId, final DSRequest request, final DSResponse response ) { GWT.log( "Issue fetch request " + requestId ); final CustomerRequestFactory.CustomerRequest rfreq = requestFactory.custRequest(); int startRow = request.getStartRow(); int endRow = request.getEndRow(); rfreq.fetchCustomers( startRow, endRow ).fire( new Receiver<List<CustomerProxy>>() { @Override public void onSuccess( List<CustomerProxy> customers ) { List<Record> records = new ArrayList<Record>(); for ( CustomerProxy customer : customers ) { GWT.log( "Creating a record for customer " + customer.getId() ); ListGridRecord r = new ListGridRecord(); r.setAttribute( "id", customer.getId() ); r.setAttribute( "name", customer.getCustomerName() ); records.add( r ); } Record[] arr = new Record[records.size()]; GWT.log( "Returning " + arr.length + " records" ); response.setData( records.toArray( arr ) ); GWT.log( "Processing request " + requestId ); processResponse( requestId, response ); } @Override public void onFailure(ServerFailure error) { GWT.log("FAIL: " + error.getMessage()); response.setStatus( RPCResponse.STATUS_FAILURE ); processResponse( requestId, response ); } } ); }
Code:
@Inject public AdminHome(CustomerDataSource ds) { GWT.log("initializing home"); this.ds = ds; layout = new VLayout(15); initWidget(layout); grid = new ListGrid(); grid.setAlwaysShowEditors(true); grid.setWidth(550); grid.setHeight(224); grid.setShowAllRecords(true); grid.setCellHeight(22); grid.setDataSource(ds); layout.addChild(grid); grid.fetchData(); }
Leave a comment: