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

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

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

UI.beforeClientResponse介绍

[英]Registers a task to be executed before the response is sent to the client. The tasks are executed in order of registration. If tasks register more tasks, they are executed after all already registered tasks for the moment.

Example: three tasks are submitted, A, B and C, where B produces two more tasks during execution, D and E. The resulting execution would be ABCDE.

If the Component related to the task is not attached to the document by the time the task is evaluated, the execution is postponed to before the next response.

The task receives a ExecutionContext as parameter, which contains information about the component state before the response.
[中]在将响应发送到客户端之前注册要执行的任务。任务按注册顺序执行。如果任务注册了更多的任务,它们将在当前所有已注册的任务之后执行。
示例:提交了三个任务A、B和C,其中B在执行过程中产生了两个以上的任务D和E。由此产生的执行将是ABCDE。
如果在评估任务时,与任务相关的组件尚未附加到文档,则执行将推迟到下一个响应之前。
任务接收ExecutionContext作为参数,该参数包含有关响应前组件状态的信息。

代码示例

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

private void queueBeforeExecutionCallback() {
  if (lifecycleOwner == null || !lifecycleOwner.getUI().isPresent()) {
    return;
  }
  if (executionRegistration != null) {
    executionRegistration.remove();
  }
  executionRegistration = lifecycleOwner.getUI().get()
      .beforeClientResponse(lifecycleOwner,
          beforeClientResponseConsumer);
}

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

private void runBeforeClientResponse(Consumer<UI> command) {
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> command.accept(ui)));
}

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

private void runBeforeClientResponse(SerializableConsumer<UI> command) {
    getElement().getNode().runWhenAttached(ui -> ui
        .beforeClientResponse(this, context -> command.accept(ui)));
  }
}

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

@Override
protected void onAttach(AttachEvent attachEvent) {
  super.onAttach(attachEvent);
  attachEvent.getUI().beforeClientResponse(this, context -> {
    drawChart();
    if (configuration != null) {
      // Start listening to data series events once the chart has been
      // drawn.
      configuration.addChangeListener(changeListener);
    }
  });
}

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

void runBeforeClientResponse(SerializableConsumer<UI> command) {
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> command.accept(ui)));
}

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

private void runBeforeClientResponse(SerializableConsumer<UI> command) {
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> command.accept(ui)));
}

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

void runBeforeClientResponse(SerializableConsumer<UI> command) {
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> command.accept(ui)));
}

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

void runBeforeClientResponse(SerializableConsumer<UI> command) {
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> command.accept(ui)));
}

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

private void attachComponentTemplate() {
    deferredJob = new AttachComponentTemplate();
    getElement().getNode().runWhenAttached(ui -> ui
        .beforeClientResponse(this, context -> deferredJob.accept(ui)));
  }
}

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

private void beforeOpen() {
  if (getElement().getNode().getParent() == null) {
    UI ui = getCurrentUI();
    ui.beforeClientResponse(ui, context -> {
      ui.add(this);
      autoAddedToTheUi = true;
    });
  }
}

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

private void ensureAttached() {
    if (getElement().getNode().getParent() == null) {
      UI ui = getCurrentUI();
      ui.beforeClientResponse(ui, context -> {
        ui.add(this);
        autoAddedToTheUi = true;
      });
    }
  }
}

代码示例来源: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/vaadin-notification-flow

/**
 * Opens or closes the notification.
 * <p>
 * Note: You don't need to add the component anywhere before opening it.
 * Since {@code <vaadin-notification>}'s location in the DOM doesn't really
 * matter, opening a notification will automatically add it to the
 * {@code <body>} if it's not yet attached anywhere.
 *
 * @param opened
 *            {@code true} to open the notification, {@code false} to close
 *            it
 */
@Override
public void setOpened(boolean opened) {
  UI ui = UI.getCurrent();
  if (ui == null) {
    throw new IllegalStateException("UI instance is not available. "
        + "It means that you are calling this method "
        + "out of a normal workflow where it's always implicitely set. "
        + "That may happen if you call the method from the custom thread without "
        + "'UI::access' or from tests without proper initialization.");
  }
  if (opened && getElement().getNode().getParent() == null) {
    ui.beforeClientResponse(ui, context -> {
      ui.add(this);
      autoAddedToTheUi = true;
    });
  }
  super.setOpened(opened);
}

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

/**
 * Default constructor. Create an empty notification with component support
 * and non-auto-closing
 * <p>
 * Note: To mix text and child components in notification that also supports
 * child components, use the {@link Text} component for the textual parts.
 */
public Notification() {
  initBaseElementsAndListeners();
  getElement().getNode().runWhenAttached(ui -> ui
      .beforeClientResponse(this, context -> deferredJob.accept(ui)));
  setPosition(DEFAULT_POSITION);
  setDuration(0);
}

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

/**
 * Sets the checked state of this item. A checked item displays a checkmark
 * icon next to it. The checked state is also toggled by clicking the item.
 * <p>
 * Note that the item needs to be explicitly set as checkable via
 * {@link #setCheckable(boolean)} in order to check it.
 *
 * @param checked
 *            {@code true} to check this item, {@code false} to un-check it
 * @throws IllegalStateException
 *             if trying to check the item when it's checkable
 */
public void setChecked(boolean checked) {
  if (isChecked() == checked) {
    return;
  }
  if (!checkable && checked) {
    throw new IllegalStateException(
        "Trying to set a non-checkable menu item checked. "
            + "Use setCheckable() to make the item checkable first.");
  }
  getElement().setProperty("_checked", checked);
  getElement().getNode().runWhenAttached(
      ui -> ui.beforeClientResponse(this, context -> {
        ui.getPage().executeJavaScript(
            "window.Vaadin.Flow.contextMenuConnector.setChecked($0, $1)",
            getElement(), checked);
      }));
}

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

ui -> ui.beforeClientResponse(this, context -> ui.getPage()
    .executeJavaScript("$0.listenOn=$1", this, target)));
ui -> ui.beforeClientResponse(target, context -> {
  ui.getInternals()
      .addComponentDependencies(ContextMenuBase.class);

相关文章