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

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

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

UI.getCurrent介绍

[英]Gets the currently used UI. The current UI is automatically defined when processing requests to the server. In other cases, (e.g. from background threads), the current UI is not automatically defined.

The UI is stored using a weak reference to avoid leaking memory in case it is not explicitly cleared.
[中]获取当前使用的UI。当前UI在处理对服务器的请求时自动定义。在其他情况下(例如,来自后台线程),当前UI不会自动定义。
UI使用弱引用进行存储,以避免在未明确清除时泄漏内存。

代码示例

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

private UI getUI() {
    UI ui = UI.getCurrent();
    if (ui == null) {
      throw new IllegalStateException(
          "There is no UI available. The UI scope is not active");
    }
    return ui;
  }
}

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

private UI getCurrentUI() {
    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 implicitly set. "
          + "That may happen if you call the method from the custom thread without "
          + "'UI::access' or from tests without proper initialization.");
    }
    return ui;
  }
}

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

private UI getCurrentUI() {
  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 implicitly set. "
        + "That may happen if you call the method from the custom thread without "
        + "'UI::access' or from tests without proper initialization.");
  }
  return ui;
}

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

private UI getUI() {
    UI ui = UI.getCurrent();
    if (ui == null) {
      throw new IllegalStateException(
          "There is no UI available. The UI scope is not active");
    }
    return ui;
  }
}

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

private Locale findLocale() {
  Locale locale = null;
  if (UI.getCurrent() != null) {
    locale = UI.getCurrent().getLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  return locale;
}

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

/**
 * Finds an appropriate locale to be used in conversion and validation.
 *
 * @return the found locale, not null
 */
protected static Locale findLocale() {
  Locale locale = null;
  if (UI.getCurrent() != null) {
    locale = UI.getCurrent().getLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  return locale;
}

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

@Override
public boolean isActive() {
  return VaadinSession.getCurrent() != null
      && UI.getCurrent() != null
      && contextualStorageManager != null;
}

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

/**
 * Get the {@link DeviceInfo} for the current UI, if available.
 * @return Optional {@link DeviceInfo} for the current UI
 */
static Optional<DeviceInfo> get() {
  final UI ui = UI.getCurrent();
  if (ui != null) {
    return get(ui);
  }
  return Optional.empty();
}

代码示例来源:origin: org.rapidpm.vaadin/rapidpm-vaadin-cdi-m-impl

@Override
public boolean isActive() {
  return VaadinSession.getCurrent() != null
      && UI.getCurrent() != null
      && contextualStorageManager != null;
}

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

@Override
public boolean isActive() {
  return VaadinSession.getCurrent() != null
      && UI.getCurrent() != null
      && contextualStorageManager != null;
}

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

public ContextualStorage getContextualStorage(boolean createIfNotExist) {
  final Integer uiId = UI.getCurrent().getUIId();
  return super.getContextualStorage(uiId, createIfNotExist);
}

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

@Override
protected ContextualStorage newContextualStorage(Integer uiId) {
  UI.getCurrent().addDetachListener(this::destroy);
  return super.newContextualStorage(uiId);
}

代码示例来源:origin: org.rapidpm.vaadin/rapidpm-vaadin-cdi-m-impl

@Override
protected ContextualStorage newContextualStorage(Integer uiId) {
  UI.getCurrent().addDetachListener(this::destroy);
  return super.newContextualStorage(uiId);
}

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

@Override
protected ContextualStorage newContextualStorage(Integer uiId) {
  UI.getCurrent().addDetachListener(this::destroy);
  return super.newContextualStorage(uiId);
}

代码示例来源:origin: org.rapidpm.vaadin/rapidpm-vaadin-cdi-m-impl

public ContextualStorage getContextualStorage(boolean createIfNotExist) {
  final Integer uiId = UI.getCurrent().getUIId();
  return super.getContextualStorage(uiId, createIfNotExist);
}

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

public ContextualStorage getContextualStorage(boolean createIfNotExist) {
  final Integer uiId = UI.getCurrent().getUIId();
  return super.getContextualStorage(uiId, createIfNotExist);
}

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

public void navigateTo() {
  UI.getCurrent().navigate(getRoute());
}

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

/**
 * Convenience constructor to create a date picker with a pre-selected date
 * in current UI locale format.
 *
 * @param initialDate
 *            the pre-selected date in the picker
 * @see #setValue(Object)
 */
public DatePicker(LocalDate initialDate) {
  super(initialDate, null, String.class, PARSER, FORMATTER);
  getElement().synchronizeProperty("invalid", "invalid-changed");
  setLocale(UI.getCurrent().getLocale());
}

相关文章