com.vaadin.flow.component.UI.getRouter()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中com.vaadin.flow.component.UI.getRouter()方法的一些代码示例,展示了UI.getRouter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UI.getRouter()方法的具体详情如下:
包路径:com.vaadin.flow.component.UI
类名称:UI
方法名:getRouter

UI.getRouter介绍

[英]Gets the router used for navigating in this UI.
[中]获取用于在此UI中导航的路由器。

代码示例

代码示例来源:origin: com.vaadin/flow-server

private <T> NavigationState getNavigationState(String route,
    List<T> routeParams) {
  List<String> segments = routeParams.stream().map(Object::toString)
      .collect(Collectors.toList());
  Class<? extends Component> target = getTargetOrThrow(route, segments);
  if (!routeParams.isEmpty()) {
    checkUrlParameterType(routeParams.get(0), target);
  }
  return new NavigationStateBuilder(ui.getRouter())
      .withTarget(target, segments).build();
}

代码示例来源:origin: appreciated/vaadin-app-layout

public String getRoute() {
  if (className != null) {
    return UI.getCurrent().getRouter().getUrl(className);
  } else if (view != null) {
    return UI.getCurrent().getRouter().getUrl(view.getClass());
  } else {
    return getCaption();
  }
}

代码示例来源:origin: appreciated/vaadin-app-layout

public String getRoute() {
  if (className != null) {
    return UI.getCurrent().getRouter().getUrl(className);
  } else if (view != null) {
    return UI.getCurrent().getRouter().getUrl(view.getClass());
  } else {
    return getCaption();
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Finds the class on on which page configuration annotation should be
 * defined.
 *
 * @param ui
 *            the UI for which to do the lookup, not <code>null</code>
 * @param request
 *            the request for which to do the lookup, not <code>null</code>
 * @return the class for which page configuration annotations should be
 *         defined, or an empty optional if no such class is available
 */
public static Optional<Class<?>> resolvePageConfigurationHolder(UI ui,
    VaadinRequest request) {
  assert ui != null;
  assert request != null;
  if (ui.getRouter() == null) {
    return Optional.empty();
  }
  return ui.getRouter().resolveNavigationTarget(request.getPathInfo(),
      request.getParameterMap()).map(navigationState -> {
        Class<? extends RouterLayout> parentLayout = getTopParentLayout(
            ui.getRouter(), navigationState);
        if (parentLayout != null) {
          return parentLayout;
        }
        return navigationState.getNavigationTarget();
      });
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Forward the navigation to show the given component instead of the
 * component that is currently about to be displayed.
 *
 * @param forwardTargetComponent
 *            the component type to display, not {@code null}
 */
public void forwardTo(Class<? extends Component> forwardTargetComponent) {
  Objects.requireNonNull(forwardTargetComponent,
      "forwardTargetComponent cannot be null");
  forwardTo(new NavigationStateBuilder(ui.getRouter())
      .withTarget(forwardTargetComponent).build());
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Reroutes the navigation to show the given component instead of the
 * component that is currently about to be displayed.
 *
 * @param routeTargetType
 *            the component type to display, not {@code null}
 */
public void rerouteTo(Class<? extends Component> routeTargetType) {
  Objects.requireNonNull(routeTargetType,
      "routeTargetType cannot be null");
  rerouteTo(new NavigationStateBuilder(ui.getRouter())
      .withTarget(routeTargetType).build());
}

代码示例来源:origin: com.vaadin/flow-server

List<Class<? extends RouterLayout>> routeLayouts = ui.getRouter()
    .getRegistry().getRouteLayouts(path,
        (Class<? extends Component>) navigationTarget);

代码示例来源:origin: com.vaadin/flow-server

/**
 * Updates this UI to show the view corresponding to the given navigation
 * target.
 * <p>
 * Besides the navigation to the {@code location} this method also updates
 * the browser location (and page history).
 *
 * @param navigationTarget
 *            navigation target to navigate to
 */
public void navigate(Class<? extends Component> navigationTarget) {
  RouteConfiguration configuration = RouteConfiguration
      .forRegistry(getRouter().getRegistry());
  navigate(configuration.getUrl(navigationTarget));
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Reroute to error target for given exception with given custom message.
 *
 * @param exception
 *            exception to get error target for
 * @param customMessage
 *            custom message to send to error target
 */
public void rerouteToError(Exception exception, String customMessage) {
  Optional<ErrorTargetEntry> maybeLookupResult = getSource()
      .getErrorNavigationTarget(exception);
  if (maybeLookupResult.isPresent()) {
    ErrorTargetEntry lookupResult = maybeLookupResult.get();
    rerouteTargetState = new NavigationStateBuilder(ui.getRouter())
        .withTarget(lookupResult.getNavigationTarget()).build();
    rerouteTarget = new ErrorStateRenderer(rerouteTargetState);
    errorParameter = new ErrorParameter<>(
        lookupResult.getHandledExceptionType(), exception,
        customMessage);
  } else {
    throw new RuntimeException(customMessage, exception);
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Updates this UI to show the view corresponding to the given navigation
 * target with the specified parameter. The parameter needs to be the same
 * as defined in the route target HasUrlParameter.
 * <p>
 * Besides the navigation to the {@code location} this method also updates
 * the browser location (and page history).
 * <p>
 * Note! A {@code null} parameter will be handled the same as
 * navigate(navigationTarget) and will throw an exception if HasUrlParameter
 * is not @OptionalParameter or @WildcardParameter.
 *
 * @param navigationTarget
 *            navigation target to navigate to
 * @param parameter
 *            parameter to pass to view
 * @param <T>
 *            url parameter type
 * @param <C>
 *            navigation target type
 */
public <T, C extends Component & HasUrlParameter<T>> void navigate(
    Class<? extends C> navigationTarget, T parameter) {
  RouteConfiguration configuration = RouteConfiguration
      .forRegistry(getRouter().getRegistry());
  navigate(configuration.getUrl(navigationTarget, parameter));
}

代码示例来源:origin: com.vaadin/flow-server

getRouter().navigate(this, navigationLocation,
    NavigationTrigger.PROGRAMMATIC);

代码示例来源:origin: com.vaadin/flow-server

private Router getRouter() {
  Router router = null;
  if (getElement().getNode().isAttached()) {
    StateTree tree = (StateTree) getElement().getNode().getOwner();
    router = tree.getUI().getRouter();
  }
  if (router == null) {
    router = VaadinService.getCurrent().getRouter();
  }
  if (router == null) {
    throw new IllegalStateException(
        "Implicit router instance is not available. "
            + "Use overloaded method with explicit router parameter.");
  }
  return router;
}

代码示例来源:origin: com.vaadin/vaadin-app-layout-flow

@Override
public void showRouterLayoutContent(HasElement content) {
  Component component = content.getElement().getComponent().get();
  String target = null;
  if (component instanceof RouteNotFoundError) {
    getAppLayoutMenu().selectMenuItem(null);
  } else {
    target = UI.getCurrent().getRouter()
        .getUrl(component.getClass());
    getAppLayoutMenu().getMenuItemTargetingRoute(target)
        .ifPresent(item -> getAppLayoutMenu().selectMenuItem(item, false));
  }
  beforeNavigate(target, content);
  getAppLayout().setContent(content.getElement());
  afterNavigate(target, content);
}

代码示例来源:origin: com.vaadin/flow-server

private static InitialPageSettings createInitialPageSettingsObject(
    BootstrapHandler.BootstrapContext context) {
  UI ui = context.getUI();
  VaadinRequest request = context.getRequest();
  WebBrowser browser = context.getSession().getBrowser();
  String pathInfo = request.getPathInfo();
  if (pathInfo == null) {
    pathInfo = "";
  } else {
    assert pathInfo.startsWith("/");
    pathInfo = pathInfo.substring(1);
  }
  Router router = ui.getRouter();
  NavigationEvent navigationEvent = new NavigationEvent(router,
      new Location(pathInfo,
          QueryParameters.full(request.getParameterMap())),
      ui, NavigationTrigger.PAGE_LOAD);
  List<HasElement> components = ui.getChildren()
      .map(component -> (HasElement) component)
      .collect(Collectors.toList());
  AfterNavigationEvent afterNavigationEvent = new AfterNavigationEvent(
      new LocationChangeEvent(navigationEvent.getSource(),
          navigationEvent.getUI(), navigationEvent.getTrigger(),
          navigationEvent.getLocation(), components));
  return new InitialPageSettings(request, ui, afterNavigationEvent,
      browser);
}

代码示例来源:origin: com.vaadin/flow-server

if (ui.getRouter() != null) {
  ui.getRouter().initializeUI(ui, request);

代码示例来源:origin: com.vaadin/flow-server

.getNavigationTarget();
List<Class<? extends RouterLayout>> routeLayoutTypes = getRouterLayoutTypes(
    routeTargetType, ui.getRouter());

相关文章