1

我想知道 Scout 是否有办法在不同的链接上制作不同的表格。现在所有表单都在相同的 url 链接上打开。例如,如果应用程序在http://localhost:1808/上运行,打开人员表单后,此表单在链接http://localhost:1808/person?id=300中打开。

有没有办法做到这一点?

4

2 回答 2

4

Deep-Link 功能在 release/6.0.x 分支上可用,工作原理如下:

您可以将 URL 参数“dl”传递给 Scout servlet。“dl”-参数包含以下格式的字符串:[handler name]-[data]。示例:form-123456

对于要在 Scout 应用程序中处理的每个深层链接模式,您必须注册一个深层链接处理程序,该处理程序实现 IDeepLinkHandler 并且通常从 AbstractDeepLinkHandler 继承。在构造函数中,您指定一个与您的深层链接模式匹配的正则表达式,并将数据提取为正则表达式组。在 handleImpl 方法中,您可以实现深度链接在 Scout 模型中应该执行的任何操作。深度链接处理程序将自动注册为 (Scout) Bean。

下面是一些示例代码,用于打开带有深层链接的 Scout 表单:

public class FormDeepLinkHandler extends AbstractDeepLinkHandler {

  private static final String HANDLER_NAME = "form";

  public FormDeepLinkHandler() {
    super(defaultPattern(HANDLER_NAME, "\\d+"));
  }

  @Override
  public void handleImpl(Matcher matcher) throws DeepLinkException {
    String formId = matcher.group(1);
    IForm form = getFormById(formId);
    form.start();
  }

  private IForm getFormById(String formId) throws DeepLinkException {
    if ("300".equals(formId)) {
      return new ScoutInfoForm();
    }
    // throw a DeepLinkException when resource requested by deep-link does not exist
    throw new DeepLinkException("Form not found");
  }

  public BrowserHistoryEntry createBrowserHistoryEntry(IForm form) {
    return DeepLinkUriBuilder.createRelative()
        .parameterInfo(form.getTitle())
        .parameterPath(toDeepLinkPath(getFormId(form)))
        .createBrowserHistoryEntry();
  }

  private String getFormId(IForm form) {
    // TODO: return an ID for different forms, or you could use form.getFormId();
    return "300";
  }

  @Override
  public String getName() {
    return HANDLER_NAME;
  }

}

可选的 createBrowserHistoryEntry(IForm) 创建一个要在浏览器历史记录中使用的条目,这意味着它将更改浏览器地址栏中的 URL。它还可以在 Scout 应用程序中使用历史后退/前进按钮。为此,您可以在您的表单中执行此操作:

  @Override
  protected void execInitForm() {
    BrowserHistoryEntry entry = BEANS.get(FormDeepLinkHandler.class).createBrowserHistoryEntry(this);
    ClientSessionProvider.currentSession().getDesktop().setBrowserHistoryEntry(entry);
  }

有了它,您最终可以通过打开 URL 来开始您的表单:http:
//foo.com/?dl= form-300&i=Title-of-the-form

注意:“i”参数是完全可选的。您可以使用它使 URL 对人类更具可读性或作为搜索爬虫的提示。

于 2016-04-05T07:03:29.743 回答
0

您正在寻找的关键字是“深层链接”。恐怕我们没有很多关于它的文档,因为该功能仍在开发中。第一个版本添加了 Neon.M6。

目标是能够使用特定 URL 跳转到应用程序中的某个位置。

此功能还可以使用 Web 浏览器中的后退/前进按钮(有一些限制)。

我们的小部件演示应用程序中有一个实现示例:

http://<URL to the APP>/?deeplink=widget-svgfield

注意:参数的名称将来可能会从dlandi而不是deeplinkand更改info

于 2016-04-05T05:51:00.510 回答