Scout Eclipse在服务器端提供可选消息 [英] Scout Eclipse present optional message on server side

查看:206
本文介绍了Scout Eclipse在服务器端提供可选消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这样做的原因是保存在警告中。



例如,你有一些逻辑来保存一些实体,并且在后台这个实体有一些有效性。
在某些情况下,用户需要通知保存此记录可能会导致一些问题,所以他需要确认保存。



现在我有这样的实现:

 侦察客户端 - >侦察服务器 - >后端 - >侦察服务器 - >侦察客户端 - >侦察服务器 - > Scout后端
将调用pass参数保存到后端尝试保存;返回excaption返回异常到客户端现在弹出发送参数强制力保存

但我不喜欢那里客户端你需要处理这个。
如果客户端只调用保存,那么将会更好,所有这些都将在侦察服务器和后端处理。



有更好的方法吗? p>

Marko

解决方案

我不知道你想如何处理这个服务器只需一边。



如果您需要与用户进行一些用户交互,就像这样:现有数据将被覆盖您的业​​务逻辑在后端)和您确定要保存吗?,您需要在应用程序的客户端部分执行此操作。否则,您不能中断现有流程,通知您的用户并让表单打开。



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



以下是存储方法(客户端)可能如下所示的草图:

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

//首先调用store方法:
SaveResult result = service.store(formData,SaveState.TRY);

//第一次调用的句柄结果:
if(result.getState()== SaveResultState.SUCCESSFUL){
importFormData(result.getFormData());
}
else if(result.getState()== SaveResultState.NEEDS_CONFIRMATION){
int button = MessageBox.showYesNoCancelMessage(null,某些需要在后端确认,你想保存?);
开关(按钮){
case MessageBox.YES_OPTION:{
//使用其他标志调用store方法:
result = service.store(formData,SaveState.FORCE) ;

//第二次调用的句柄结果:
if(result.getState()== SaveResultState.SUCCESSFUL){
importFormData(result.getFormData());
}
else {
抛出新的ProcessingException(service.store()不是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可能是一个通用的参数)。



如果你有很多次这样的模式,很容易让它足够通用表单(带接口和抽象类)。这样你只会写这个处理一次(服务器中的一部分,客户端的一部分)。


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

解决方案

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

这篇关于Scout Eclipse在服务器端提供可选消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆