Scout Eclipse present optional message on server side

我的梦境 提交于 2019-12-09 03:56:15

问题


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:


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).



来源:https://stackoverflow.com/questions/32439006/scout-eclipse-present-optional-message-on-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!