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

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

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

UI.getPage介绍

[英]Gets the object representing the page on which this UI exists.
[中]获取表示此UI所在页面的对象。

代码示例

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

/**
 * Navigates forward. This has the same effect as if the user would press
 * the forward button in the browser. This causes a
 * {@link HistoryStateChangeEvent} to be fired asynchronously if the
 * conditions described in the <a href=
 * "https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate">
 * onpopstate documentation</a> are met.
 */
public void forward() {
  ui.getPage().executeJavaScript("history.forward()");
}

代码示例来源:origin: vaadin/spring

@Override
protected void execute(UI ui) {
  ui.getPage().executeJavaScript("$0.innerText='from execJS'", label);
}

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

/**
 * Navigates back. This has the same effect as if the user would press the
 * back button in the browser. This causes a {@link HistoryStateChangeEvent}
 * to be fired asynchronously if the conditions described in the <a href=
 * "https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate">
 * onpopstate documentation</a> are met.
 */
public void back() {
  ui.getPage().executeJavaScript("history.back()");
}

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

private void listenerIsUnregistered() {
    windowResizeListenersSize--;
    if (windowResizeListenersSize == 0) {
      // remove JS listener
      getUI().get().getPage().executeJavaScript("$0.resizeRemove()",
          this);
    }
  }
}

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

private ResizeEvent(ResizeEventReceiver source, int width, int height) {
  super(source, true);
  apiEvent = new BrowserWindowResizeEvent(
      source.getUI().get().getPage(), width, height);
}

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

private void initConnector() {
  getUI().orElseThrow(() -> new IllegalStateException(
      "Connector can only be initialized for an attached IronList"))
      .getPage().executeJavaScript(
          "window.Vaadin.Flow.ironListConnector.initLazy($0)",
          getElement());
}

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

/**
 * Invokes <code>history.replaceState</code> in the browser with the given
 * parameters.
 *
 * @param state
 *            the JSON state to push to the history stack, or
 *            <code>null</code> to only change the location
 * @param location
 *            the new location to set in the browser, or <code>null</code>
 *            to only change the JSON state
 */
public void replaceState(JsonValue state, Location location) {
  // Second parameter is title which is currently ignored according to
  // https://developer.mozilla.org/en-US/docs/Web/API/History_API
  ui.getPage().executeJavaScript("history.replaceState($0, '', $1)",
      state, location.getPathWithQueryParameters());
}

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

private static void updatePageTitle(NavigationEvent navigationEvent,
    Component routeTarget) {
  String title;
  if (routeTarget instanceof HasDynamicTitle) {
    title = ((HasDynamicTitle) routeTarget).getPageTitle();
  } else {
    title = lookForTitleInTarget(routeTarget).map(PageTitle::value)
        .orElse("");
  }
  navigationEvent.getUI().getPage().setTitle(title);
}

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

private void initConnector() {
  runBeforeClientResponse(ui -> ui.getPage().executeJavaScript(
      "window.Vaadin.Flow.datepickerConnector.initLazy($0)",
      getElement()));
}

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

private void initConnector() {
  runBeforeClientResponse(ui -> {
    ui.getPage().executeJavaScript(
        "window.Vaadin.Flow.selectConnector.initLazy($0)",
        getElement());
    // connector init will handle first data setting
    resetPending = false;
  });
}

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

private void initConnector() {
  // can't run this with getElement().executeJavaScript(...) since then
  // setLocale might be called before this causing client side error
  runBeforeClientResponse(ui -> ui.getPage().executeJavaScript(
      "window.Vaadin.Flow.timepickerConnector.initLazy($0)",
      getElement()));
}

代码示例来源:origin: vaadin/spring

@Override
protected void onAttach(AttachEvent attachEvent) {
  super.onAttach(attachEvent);
  UI ui = attachEvent.getUI();
  elementTest.addClickListener(e -> {
    new Thread(new ElementAPI(ui)).start();
  });
  execJsTest.addClickListener(e -> {
    new Thread(new ExecJS(ui)).start();
  });
  ui.getPage().executeJavaScript(
      "$0.setText = function(text) {$0.innerText=text;}", label);
  callFunctionTest.addClickListener(e -> {
    new Thread(new CallFunction(ui)).start();
  });
}

代码示例来源:origin: com.vaadin/flow-component-demo-helpers

private void showTab(String tabUrl) {
  Div tab = tabComponents.get(tabUrl);
  if (tab != null) {
    container.removeAll();
    container.add(tab);
    navBar.setActive(getTabUrl(tabUrl));
    tab.getElement().getNode().runWhenAttached(ui -> ui.getPage()
        .executeJavaScript("Prism.highlightAll();"));
  }
}

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

private static <T> void setupTemplateRendererEventHandler(UI ui,
    Element eventOrigin, String handlerName, Consumer<T> consumer,
    Function<String, T> keyMapper) {
  // vaadin.sendEventMessage is an exported function at the client
  // side
  ui.getPage().executeJavaScript(String.format(
      "$0.%s = function(e) {Vaadin.Flow.sendEventMessage(%d, '%s', {key: e.model ? e.model.__data.item.key : e.target.__dataHost.__data.item.key})}",
      handlerName, eventOrigin.getNode().getId(), handlerName),
      eventOrigin);
  DomListenerRegistration registration = eventOrigin.addEventListener(
      handlerName, event -> processEventFromTemplateRenderer(event,
          handlerName, consumer, keyMapper));
  eventOrigin.addDetachListener(event -> registration.remove());
}

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

/**
 * Calls the <code>focus</code> function at the client, making the component
 * keyboard focused.
 *
 * @see <a href=
 *      "https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus">focus
 *      at MDN</a>
 */
default void focus() {
  /*
   * Make sure to call the focus function only after the element is
   * attached, and after the initial rendering cycle, so webcomponents can
   * be ready by the time when the function is called.
   */
  getElement().getNode()
      .runWhenAttached(ui -> ui.getPage().executeJavaScript(
          "setTimeout(function(){$0.focus();},0)", getElement()));
}

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

@Override
  public int handle(NavigationEvent event) {
    UI ui = event.getUI();
    Router router = event.getSource();

    ui.getPage().getHistory().replaceState(null, target);

    return router.navigate(ui, target, event.getTrigger());
  }
}

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

@Override
protected void onAttach(AttachEvent attachEvent) {
  getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(
      this,
      context -> ui.getPage().executeJavaScript(
          "$0.addEventListener('items-changed', "
              + "function(){ this.$server.updateSelectedTab(true); });",
          getElement())));
}

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

private int forward(NavigationEvent event, BeforeEvent beforeNavigation) {
  NavigationHandler handler = beforeNavigation.getForwardTarget();
  NavigationEvent newNavigationEvent = getNavigationEvent(event,
      beforeNavigation);
  newNavigationEvent.getUI().getPage().getHistory().replaceState(null,
      newNavigationEvent.getLocation());
  return handler.handle(newNavigationEvent);
}

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

private void resetContent() {
  if (updateScheduled) {
    return;
  }
  updateScheduled = true;
  runBeforeClientResponse(ui -> {
    container.removeAllChildren();
    getItems().forEach(this::resetContainers);
    int containerNodeId = createNewContainer(getChildren());
    String appId = ui.getInternals().getAppId();
    ui.getPage().executeJavaScript(
        "window.Vaadin.Flow.contextMenuConnector.generateItems($0, $1, $2)",
        getElement(), appId, containerNodeId);
    updateScheduled = false;
  });
}

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

private static void execJS(Component component, String js) {
  StateNode node = component.getElement().getNode();
  node.runWhenAttached(ui -> ui.getInternals().getStateTree()
      .beforeClientResponse(node, context -> ui.getPage()
          .executeJavaScript(js, component.getElement())));
}

相关文章