Scout Eclipse present optional message on server s

2019-03-05 08:50发布

Is there a way that message (Yes/No) is presented inside scout server?

Reason for this is save with warnings.

For example you have some logic for save some entity and some validity on this entity in backend. In some cases, user need to be inform that saving this record might lead to some trouble, so he need to confirm save.

Right now I have implementation like this :

Scout Client ->         Scout Server       ->           Backend                 ->          Scout Server          ->       Scout Client      ->    Scout Server     -> Scout Backend
save called      pass parameter to backend     try to save; return excaption         return exception to client            present popUp     sent parameter force      force save

but I don't like that inside client you need to handle this. It would be nicer if client would call only save and all will be handled in scout server and backend.

Is there a better way for this?

Marko

1条回答
乱世女痞
2楼-- · 2019-03-05 09:18

I am not sure how you want to handle this server side only.

If you need to have some user interaction with a confirmation looking like this: “Existing data will be overwritten” (or whatever your business logic is in the backend) and “Are you sure you want to save?”, you need to do it in the client part of your application. Otherwise you cannot interrupt the existing process, inform your user and let the form open.

If you do not need any user interaction, a solution "server+backend only" is possible.

Here is a sketch of how the store method (client side) could look like:

protected void execStore() throws ProcessingException {
  ICompanyService service = SERVICES.getService(ICompanyService.class);
  CompanyFormData formData = new CompanyFormData();
  exportFormData(formData);

  //first call of the store method:
  SaveResult result = service.store(formData, SaveState.TRY);

  //handle result of the first call:
  if (result.getState() == SaveResultState.SUCCESSFUL) {
    importFormData(result.getFormData());
  }
  else if (result.getState() == SaveResultState.NEEDS_CONFIRMATION) {
    int button = MessageBox.showYesNoCancelMessage(null, "Something is needs confirmation in the backend", "Do you want to save?");
    switch (button) {
      case MessageBox.YES_OPTION: {
        //Recall the store method with an other flag:
        result = service.store(formData, SaveState.FORCE);

        //handle result of the second call:
        if (result.getState() == SaveResultState.SUCCESSFUL) {
          importFormData(result.getFormData());
        }
        else {
          throw new ProcessingException("service.store() is not sucessfull");
        }
        break;
      }
      case MessageBox.NO_OPTION: {
        setFormStored(false);
        break;
      }
      case MessageBox.CANCEL_OPTION:
      default: {
        throw new VetoException("execStore() was cancelled");
      }
    }
  }
}

With SaveResult being something like that:

public class SaveResult {

  private final AbstractFormData formData;
  private final SaveResultState state;

  public SaveResult(AbstractFormData formData, SaveResultState state) {
    this.formData = formData;
    this.state = state;
  }

  public AbstractFormData getFormData() {
    return formData;
  }

  public SaveResultState getState() {
    return state;
  }
}

(If this makes sense, you could add the explanation coming from the backend and the FormData could be a generic parameter).

If you have this pattern a lot of times, it is easy to make it generic enough for all your forms (with interfaces and abstract classes). This way you write this handling only once (with a part in the server and a part in the client).

查看更多
登录 后发表回答