Hi all,
I am fairly new to Vaadin, so please bear with me.
I want to create a non-visual URL endpoint at location /callback?code=...
which:
- reads out the query parameter
code
- sets the value of query parameter
code
in the session context - redirect to
/
I already found out that:
- redirecting can be done with
UI.getCurrent().navigate("")
- session context can be controlled as explained on https://vaadin.com/docs/v8/framework/articles/SettingAndReadingSessionAttributes.html
- query parameters can be read by implementing
HasUrlParameter<String>
:public void setParameter(BeforeEvent, String) { String code: event.getLocation().getQueryParameters().getParameters().get("code"); }
But I am having troubles to create a route which combines everything.
Is there an example or basic example out there somewhere? FWIW, I am starting from the sample project as given on https://vaadin.com/start/latest/simple-ui.
I currently have the following code:
@Route(value = "code")
@PageTitle("Code")
public class CodePage extends VerticalLayout implements BeforeEnterObserver {
public CodePage() {
}
@Override
public void beforeEnter(final BeforeEnterEvent event) {
String code = event.getLocation().getQueryParameters().getParameters().get("code").get(0);
event.getUI().getSession().setAttribute("code", code);
event.rerouteTo(ReviewsList.class);
}
}
Is this a good start?
I am also wondering if there is a way to not extend from VerticalLayout
or any kind of layout, as this page will only be redirecting and thus this page will not display anything.
I am using Vaadin version 12.0.3.
Thank you, greatly appreciated!