How to program a deep link in the application?

Dear Vaadin developers,

In my application I would like to have “deep link” link, which will contain the information about the currently opened application form and data on that form (basically, a set of parameters, like “form=X&email=abc&user=12”). By navigating to this link the application should show the given form and load the appropriate data. And main questions here:

  • How to create such URL and embed all needed parameters? I obviously can’t associate the parameters using
    AbstractComponent.setData()
    , because the link will be opened in another session.
  • How to handle it if the user follows the URL in new browser session and retrieve all needed parameters to fill the form?
  • How to reset the URL in browser, after the user navigates away from the given from? (so the browser URL does not contain the “stale” information)

Thanks for any hints.

Any ideas on how can I do it in Vaadin? Were can I read more about deep navigation?

Thanks in advance.

I’m not exactly sure what you want, but you can give such parameters in the URI Fragment part of the URL. See
11.11. URI Fragment and History Management with UriFragmentUtility
.

You can use regular URL parameters and after getting them, jump to the same URL without the parameters with mainWindow.open(). It causes reloading the page, so it’s rather heavy operation.

Thanks! That is exactly what I need!

Unfortunately, does not work for me out-of-the-box: I have created
UriFragmentUtility
class instance and registered it in main window. When I invoke
uriFragmentUtility.setFragment(“openIndexedText”)
the URL in browser does not change. Do I miss something here?

Also what mothers me, is that I cant pass any symbol to URL fragment (e.g. “document=2&tab=1”). Or
UriFragmentUtility
will encode/decode that for me automatically? Anyway the URL will not be so readable, as if I pass the navigation information in main URL part.

I think you should be able to pass parameters in the ?foo=bar format in the URI fragment, although you need to parse them yourself.

As RFC 3986 says:

   fragment      = *( pchar / "/" / "?" )

   pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

   pct-encoded   = "%" HEXDIG HEXDIG

   unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
   reserved      = gen-delims / sub-delims
   gen-delims    = ":" / "/" / "?" / "#" / "[" / "]
" / "@"
   sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                 / "*" / "+" / "," / ";" / "="

Thanks,

I tried to code a simple application with
UriFragmentUtility
, but I think to miss some basics…

I have created the class field,
uriFragmentUtility
, registered it in
mainWindow
and then I am changing the fragment on button click event: nothing happens. I expect that URL in the browser should be updated… Maybe there is an working code in Vaadin sampler to play with (I failed to find one)? There is no magic in
Vaadin book example
, should work…

UriFragmentUtility uriFragmentUtility = new UriFragmentUtility();
...
mainWindow.addComponent(uriFragmentUtility);
...
/**
 * @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.ClickEvent)
 */
public void buttonClick(Button.ClickEvent event) {
	uriFragmentUtility.setFragment("openText");
}