Announcement

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

    Callback function is not called after DSResponse status set to Failure

    hi,
    I am trying to save a data record with dynamicForm.saveData(new SaveCallbackHandler()),
    which the custom class SaveCallbackHandler implementing the DSCallback class.

    At the beginning everything works fine, new data record was saved and
    SaveCallbackHandler.execute() function was being called successfully.

    But after I invoked dsResponse.setStatus() to FAILURE, the callback function is
    not called and only show the default error dialog popped up by the RPCManager.

    I have read post about setting the willHandleError to true in RPCRequest object to solve the problem.
    But how i should apply that method in dynamicForm in my case? Thank you for answering!

    Code:
    DataSource dataSource = DataSource.get("Membership");
    comboBoxMembershipType.setOptionDataSource(dataSource);
    
    saveButton.addClickHandler(new ClickHandler(){
    	public void onClick(final ClickEvent event) {
    		dynamicForm.saveData(new SaveCallbackHandler());
    	} 
    });
    dynamicForm.setFields(comboBoxMembershipType, saveButton);
    
    private class SaveCallbackHandler implements DSCallback {
    	@Override
    	public void execute(final DSResponse response, final Object obj,
    		final DSRequest request) {
    		if ( response.getStatus() == STATUS.SUCCESS) {
    			SC.say("Save successfully");
    		} else {
    			SC.say("Failed to save");
    		}
    	}
    }

    SmartGWT version: 2.5
    Firefox version: 3.6.15

    #2
    There is no need to create your own extension to DSCallback. saveData has 2 parameters that can be passed saveData(DSCallback, Properties). Therefore you can do what you want in the original saveData as follows:
    Code:
                    DSRequest request = new DSRequest();
                        request.setWillHandleError(true);
                       dynamicForm.saveData(new DSCallback() {
                            public void execute(DSResponse response, Object rawData, DSRequest request) {
                                if (response.getStatus() == 0) {
                                        SC.say("Save successfully");
                                } else {
                                        SC.say("Failed to save");
                        }, request);
    note, unless there is a specific reason to create your own version of the callback then don't do it

    Please review the Javadocs and the saveData APIs to see what is available
    Last edited by Isomorphic; 24 Oct 2011, 10:46.

    Comment


      #3
      The suggested code is working fine.Thank you!

      Comment

      Working...
      X