use of com.vaadin.flow.router.NavigationTrigger in project flow by vaadin.
the class NavigationRpcHandler method handle.
@Override
public Optional<Runnable> handle(UI ui, JsonObject invocationJson) {
History history = ui.getPage().getHistory();
HistoryStateChangeHandler historyStateChangeHandler = history.getHistoryStateChangeHandler();
if (historyStateChangeHandler != null) {
JsonValue state = invocationJson.get(JsonConstants.RPC_NAVIGATION_STATE);
String location = invocationJson.getString(JsonConstants.RPC_NAVIGATION_LOCATION);
boolean triggeredByLink = invocationJson.hasKey(JsonConstants.RPC_NAVIGATION_ROUTERLINK);
NavigationTrigger trigger = triggeredByLink ? NavigationTrigger.ROUTER_LINK : NavigationTrigger.HISTORY;
// as it would be dubious and even impossible on the client side.
if (trigger == NavigationTrigger.ROUTER_LINK && ui.getElement().getNode().isInert()) {
LoggerFactory.getLogger(NavigationRpcHandler.class.getName()).trace("Ignored router link click for location '{}' because the UI is inert.", location);
return Optional.empty();
}
HistoryStateChangeEvent event = new HistoryStateChangeEvent(history, state, new Location(location), trigger);
historyStateChangeHandler.onHistoryStateChange(event);
}
return Optional.empty();
}
use of com.vaadin.flow.router.NavigationTrigger in project flow by vaadin.
the class ApplicationRunnerServlet method createServletService.
@SuppressWarnings("serial")
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
// service doesn't use router actually. UI class is responsible to show
// and update the content by itself with only root route available
VaadinServletService service = new VaadinServletService(this, deploymentConfiguration) {
@Override
public Router getRouter() {
Router router = new Router(getRouteRegistry()) {
@Override
public int navigate(UI ui, Location location, NavigationTrigger trigger, JsonValue state) {
ui.getPage().getHistory().pushState(null, location);
return HttpServletResponse.SC_OK;
}
};
return router;
}
};
service.init();
final SystemMessagesProvider provider = service.getSystemMessagesProvider();
service.setSystemMessagesProvider((SystemMessagesProvider) systemMessagesInfo -> {
if (systemMessagesInfo.getRequest() == null) {
return provider.getSystemMessages(systemMessagesInfo);
}
Object messages = systemMessagesInfo.getRequest().getAttribute(CUSTOM_SYSTEM_MESSAGES_PROPERTY);
if (messages instanceof SystemMessages) {
return (SystemMessages) messages;
}
return provider.getSystemMessages(systemMessagesInfo);
});
return service;
}
Aggregations