Marko Zadravec
Marko Zadravec

Reputation: 8740

Scout Eclipse Neon different url for for different pages

I would like to know if there is a way in Scout to make different forms on different links. Right now all the forms open on same url links. For example if application runs on http://localhost:1808/ that after opening person form, this form open in link http://localhost:1808/person?id=300 for example.

Is there a way to do this?

Upvotes: 1

Views: 261

Answers (2)

Andre
Andre

Reputation: 178

The Deep-Link feature is available on release/6.0.x branch and works like this:

You can pass an URL parameter "dl" to the Scout servlet. The "dl"-parameter contains a string in this format: [handler name]-[data]. Example: form-123456.

For each deep-link pattern you want to process in your Scout application, you have to register a deep-link handler which implements IDeepLinkHandler and typically inherits from AbstractDeepLinkHandler. In the constructor you specify a regular expression that matches your deep-link pattern, and extracts the data as a regex-group. In the handleImpl method you implement whatever the deep-link should do in the Scout model. The deep-link handler will be automatically registered as a (Scout) Bean.

Here's some example code to open a Scout form with a deep-link:

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;
  }

}

The optional createBrowserHistoryEntry(IForm) creates an entry to be used in the browser history, which means it will change the URL in the address bar of your browser. It also enables the possibility to use the history back/forward buttons in a Scout application. For that you could do this in your form:

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

With that you can finally start your form by opening the URL:
http://foo.com/?dl=form-300&i=Title-of-the-form

Note: the "i" parameter is completely optional. You can use it to make the URL more readable for humans or as a hint for search crawlers.

Upvotes: 4

Jmini
Jmini

Reputation: 9507

The keyword you are looking for is "Deep-Links". I am afraid we do not have a lot of documentation about it, because the feature is still in development. The first version was added with Neon.M6.

The goal is to be able to jump somewhere in the application with a specific URL.

This Feature enables also the possibility to work with the Back/Forward buttons from the Web browser (with some limitations).

We have one implementation example in our Widgets demo application:

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

Note: the Name of the parameters will probably change in the future from dl and i instead of deeplink and info.

Upvotes: 0

Related Questions