【问题标题】:Scout Eclipse present optional message on server sideScout Eclipse 在服务器端显示可选消息
【发布时间】:2015-09-10 17:49:25
【问题描述】:

有没有办法在侦察服务器中显示消息(是/否)?

原因是保存时出现警告。

例如,您有一些逻辑可以在后端保存某个实体和该实体的某些有效性。 在某些情况下,用户需要被告知保存这条记录可能会带来一些麻烦,所以他需要确认保存。

现在我有这样的实现:

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

但我不喜欢你需要处理的内部客户端。 如果客户端只调用 save 并且所有都将在 scout 服务器和后端处理会更好。

有没有更好的方法?

马尔科

【问题讨论】:

    标签: dependencies server client messagebox eclipse-scout


    【解决方案1】:

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

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

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

    这是存储方法(客户端)的示意图:

    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 可以是通用参数)。

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

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2013-01-02
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 2021-09-04
      • 1970-01-01
      • 2020-09-17
      相关资源
      最近更新 更多