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

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

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

UI.add介绍

[英]Adds the given components to the UI.

The components' elements are attached to the UI element (the body tag).
[中]将给定组件添加到UI。
组件的元素附加到UI元素(body标签)。

代码示例

代码示例来源: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-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);
}

相关文章