Hello!
Please describe to me the best solution for the following situation.
- The user creates an order on my site
- The user goes to the payment gateway website (app?.page?.setLocation(url)) and makes the payment
- The payment gateway makes a redirect with the parameters back to my site, the parameters are processed and the user returns to the main page, preferably with a preserved interface.
I have a problem with point three. The request from the payment gateway comes to:
@Route("payment")
class PaymentView(...): Div(), RouterLayout, HasUrlParameter<String>
parameters are processed successfully, the user is shown a dialog with payment information and “Return”, but when he clicks the return button to the main window of the site,
fun return() {
close() //close dialog
UI.getCurrent().access { // or without UI.getCurrent().access
UI.getCurrent().page.executeJs("window.location.href = ''")
// or UI.getCurrent().page.setLocation("https://site.com/main")
// or UI.getCurrent().navigate(MainView::class.java)
}
}
UI is not displayed - just blank screen, but the address line changes correctly. When you press the f5 key to update your browser, an exception occurs:
ERROR InternalServerError There was an exception while trying to navigate to 'main'
java.lang.NullPointerException: null
at com.github.appreciated.app.layout.router.AppLayoutRouterLayoutBase.showRouterLayoutContent(AppLayoutRouterLayoutBase.java:51)
at com.vaadin.flow.component.internal.UIInternals.showRouteTarget(UIInternals.java:711)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:252)
at com.vaadin.flow.router.Router.handleNavigation(Router.java:249)
at com.vaadin.flow.router.Router.navigate(Router.java:220)
at com.vaadin.flow.router.Router.navigate(Router.java:186)
at com.vaadin.flow.router.Router.initializeUI(Router.java:93)
at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1516)
at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:472)
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1545)
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247)
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:120)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
After returning from an external site, is the user in another UI instance? How to switch to the previous one UI, where the whole site interface is?
I tried to save and load the ui from session - without results:
VaadinSession.getCurrent().setAttribute("current_ui", ui) //before redirect to external website
...
val ui = VaadinSession.getCurrent().getAttribute("current_ui") as UI?
UI.setCurrent(ui)
In the previous version of the site on Vaadin 6, requests were processed as follows:
public void transactionStart(Application application, Object transactionData) {
getPaymentRequestParameters((HttpServletRequest) transactionData); //parameters processing, ui updating
}
I found a similar situation on the forum, but without an answer
[https://vaadin.com/forum/thread/10779604/navigate-to-view-from-requesthandler-or-servlet]
(https://vaadin.com/forum/thread/10779604/navigate-to-view-from-requesthandler-or-servlet) .
My project uses Vaadin 14.2.1 in compatibilityMode=true and productionMode=true, Spring Boot 2.2.1 with Tomcat. MainView is annotated as
@PreserveOnRefresh, @SpringComponent, @UIScope