Passing url parameters to screen controller by an anomymous user

Hi, I have a question about this approach in opening screens by link, but in my case, I need to pass parameters that I specify in the url to the screen controller.
Just to give you more details. The task that I’m working on is implementing registration verification via email. So I have to send an email with a link to a screen, that supposed to catch the key as url param and give the user further instructions.
Is there a way to achieve this?
We’d really appreciate any help.

Thanks.

1 Like

Hi Paul,

To achieve this you can repeat all steps from mentioned topic with some changes:

  1. In your custom main window add method to provide url parameters:
public class DemoScreen extends AbstractMainWindow {
    public void setup(Map<String, String> requestParams) {
        // handle params
    }
}
  1. After navigating window in LinkHandler get the window and pass parameters:
public class DemoLinkHandler extends LinkHandler {
    public DemoLinkHandler(App app, String action, Map<String, String> requestParams) {
        super(app, action, requestParams);
    }

    @Override
    public boolean canHandleLink() {
        if ("demo".equals(action)) {
            return true;
        }

        return super.canHandleLink();
    }

    @Override
    public void handle() {
        if ("demo".equals(action)) {
            try {
                // open custom main window
                app.navigateTo("demo-screen");
                ((DemoScreen)app.getTopLevelWindow()).setup(requestParams);
            } finally {
                VaadinRequest request = VaadinService.getCurrentRequest();
                WrappedSession wrappedSession = request.getWrappedSession();
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
            }
        } else {
            super.handle();
        }
    }
}

Thanks, I’ll try this.

And with modern Screens API it would looks like:

public class DemoLinkHandler extends LinkHandler {

    public DemoLinkHandler(App app, String action, Map<String, String> requestParams) {
        super(app, action, requestParams);
    }

    @Override
    public boolean canHandleLink() {
        if ("demo".equals(action)) {
            return true;
        }

        return super.canHandleLink();
    }

    @Override
    public void handle() {
        if ("demo".equals(action)) {
            try {
                Screens screens = ComponentsHelper.getScreenContext(app.getAppUI().getTopLevelWindow()).getScreens();
                DemoScreen demoScreen = screens.create(DemoScreen.class, OpenMode.ROOT);
                demoScreen.setup(requestParams);
                demoScreen.show();
            } finally {
                VaadinRequest request = VaadinService.getCurrentRequest();
                WrappedSession wrappedSession = request.getWrappedSession();
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
            }
        } else {
            super.handle();
        }
    }
}
1 Like