0

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

4

1 回答 1

1

我不确定您只想如何处理此服务器端。

如果您需要通过如下所示的确认进行一些用户交互:“<em>现有数据将被覆盖”(或后端中的任何业务逻辑)和“<em>您确定要保存吗?” ,您需要在应用程序的客户端部分执行此操作。否则,您无法中断现有流程,通知您的用户并让表单打开。

如果您不需要任何用户交互,“仅服务器+后端”的解决方案是可能的。

下面是 store 方法(客户端)的示意图:

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");
      }
    }
  }
}

SaveResult 是这样的:

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;
  }
}

(如果这有意义,您可以添加来自后端的解释,并且 FormData 可以是通用参数)。

如果您多次使用这种模式,则很容易使其对所有表单(带有接口和抽象类)都足够通用。这样,您只需编写一次此处理(一部分在服务器中,一部分在客户端中)。

于 2015-09-10T09:49:25.237 回答