【问题标题】:Scout Eclipse Neon different url for for different pagesScout Eclipse Neon 不同页面的不同 url
【发布时间】:2016-07-24 09:04:07
【问题描述】:

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

有没有办法做到这一点?

【问题讨论】:

    标签: url eclipse-scout


    【解决方案1】:

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

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

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

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

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

    注意:参数名称将来可能会从dli 更改为deeplinkinfo

    【讨论】:

      【解决方案2】:

      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 对人类更具可读性或作为搜索爬虫的提示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-16
        • 2016-06-29
        • 2016-04-24
        • 2016-09-15
        • 2016-09-22
        • 2016-07-08
        • 2016-06-29
        相关资源
        最近更新 更多