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

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

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

UI.getUIId介绍

[英]Gets the id of the UI, used to identify this UI within its application when processing requests. The UI id should be present in every request to the server that originates from this UI. VaadinService#findUI(VaadinRequest) uses this id to find the route to which the request belongs.

This method is not intended to be overridden. If it is overridden, care should be taken since this method might be called in situations where UI#getCurrent() does not return this UI.
[中]获取UI的id,用于在处理请求时在其应用程序中标识此UI。UI id应该出现在从该UI发出的对服务器的每个请求中。VaadinService#findUI(VaadinRequest)使用此id查找请求所属的路由。
此方法不打算被重写。如果它被重写,则应小心,因为在UI#getCurrent()不返回此UI的情况下可能会调用此方法。

代码示例

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

BeanStore getBeanStore(UI ui) {
  BeanStore beanStore = uiStores.get(ui.getUIId());
  if (beanStore == null) {
    beanStore = new BeanStore(session);
    uiStores.put(ui.getUIId(), beanStore);
    ui.addDetachListener(this);
  }
  return beanStore;
}

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

BeanStore getBeanStore(UI ui) {
  BeanStore beanStore = uiStores.get(ui.getUIId());
  if (beanStore == null) {
    beanStore = new BeanStore(session);
    uiStores.put(ui.getUIId(), beanStore);
    ui.addDetachListener(this);
  }
  return beanStore;
}

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

/**
 * Adds an initialized UI to this session.
 *
 * @param ui
 *         the initialized UI to add.
 */
public void addUI(UI ui) {
  checkHasLock();
  if (ui.getUIId() == -1) {
    throw new IllegalArgumentException(
        "Can not add an UI that has not been initialized.");
  }
  if (ui.getSession() != this) {
    throw new IllegalArgumentException(
        "The UI belongs to a different session");
  }
  uIs.put(ui.getUIId(), ui);
}

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

/**
 * Generates URI string for a dynamic resource using its {@code id} and
 * {@code name}. [0] UIid, [1] sec key, [2] name
 *
 * @param name
 *            file or attribute name to use in path
 * @param id
 *            unique resource id
 * @return generated URI string
 */
public static String generateURI(String name, String id) {
  StringBuilder builder = new StringBuilder(DYN_RES_PREFIX);
  try {
    builder.append(UI.getCurrent().getUIId()).append(PATH_SEPARATOR);
    builder.append(id).append(PATH_SEPARATOR);
    builder.append(
        URLEncoder.encode(name, StandardCharsets.UTF_8.name()));
  } catch (UnsupportedEncodingException e) {
    // UTF8 has to be supported
    throw new RuntimeException(e);
  }
  return builder.toString();
}

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

private void destroy(DetachEvent event) {
    final int uiId = event.getUI().getUIId();
    super.destroy(uiId);
  }
}

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

private void destroy(DetachEvent event) {
    final int uiId = event.getUI().getUIId();
    super.destroy(uiId);
  }
}

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

/**
 * Called by the framework to remove an UI instance from the session because
 * it has been closed.
 *
 * @param ui
 *         the UI to remove
 */
public void removeUI(UI ui) {
  checkHasLock();
  assert UI.getCurrent() != null : "Current UI cannot be null";
  assert ui != null : "Removed UI cannot be null";
  assert UI.getCurrent().getUIId() == ui.getUIId() : "UIs don't match";
  ui.getInternals().setSession(null);
  uIs.remove(ui.getUIId());
}

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

private void destroy(DetachEvent event) {
    final int uiId = event.getUI().getUIId();
    super.destroy(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: vaadin/cdi

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

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

@Override
public void onComponentEvent(DetachEvent event) {
  assert session.hasLock();
  UI ui = event.getUI();
  BeanStore beanStore = uiStores.remove(ui.getUIId());
  if (beanStore != null) {
    beanStore.destroy();
  }
}

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

@Override
public void onComponentEvent(DetachEvent event) {
  assert session.hasLock();
  UI ui = event.getUI();
  BeanStore beanStore = uiStores.remove(ui.getUIId());
  if (beanStore != null) {
    beanStore.destroy();
  }
}

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

/**
 * Removes those UIs from the given session for which {@link UI#isClosing()
 * isClosing} yields true.
 *
 * @param session
 */
private void removeClosedUIs(final VaadinSession session) {
  List<UI> uis = new ArrayList<>(session.getUIs());
  for (final UI ui : uis) {
    if (ui.isClosing()) {
      ui.accessSynchronously(() -> {
        getLogger().debug("Removing closed UI {}", ui.getUIId());
        session.removeUI(ui);
      });
    }
  }
}

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

@Override
public String getConversationId() {
  return getVaadinSession().getSession().getId() + "-UI:"
      + getUI().getUIId();
}

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

@Override
protected void onAttach(AttachEvent attachEvent) {
  Label label = new Label(String.valueOf(getUI().get().getUIId()));
  label.setId("ui-id");
  add(label);
  RouterLink link = new RouterLink("foo", FooNavigationTarget.class);
  link.setId("foo");
  add(link);
}

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

@Override
public String getConversationId() {
  return getVaadinSession().getSession().getId() + "-UI:"
      + getUI().getUIId();
}

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

protected static JsonObject getApplicationParameters(
    BootstrapContext context) {
  JsonObject appConfig = getApplicationParameters(context.getRequest(),
      context.getSession());
  appConfig.put(ApplicationConstants.UI_ID_PARAMETER,
      context.getUI().getUIId());
  return appConfig;
}

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

@Override
  protected void onAttach(AttachEvent attachEvent) {
    Div uiId = new Div();
    uiId.setId("ui-injected");
    uiId.setText(String.valueOf(ui.getUIId()) + ui.hashCode());

    Div currentUi = new Div();
    currentUi.setText(String.valueOf(UI.getCurrent().getUIId())
        + UI.getCurrent().hashCode());
    currentUi.setId("ui-current");

    Div sessionDiv = new Div();
    sessionDiv.setText(session.getCsrfToken() + session.hashCode());
    sessionDiv.setId("session-injected");

    Div sessionCurrent = new Div();
    sessionCurrent.setText(VaadinSession.getCurrent().getCsrfToken()
        + VaadinSession.getCurrent().hashCode());
    sessionCurrent.setId("session-current");

    add(uiId, currentUi, sessionDiv, sessionCurrent);

  }
}

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

/**
 * Closes those UIs in the given session for which {@link #isUIActive}
 * yields false.
 */
private void closeInactiveUIs(VaadinSession session) {
  final String sessionId = session.getSession().getId();
  for (final UI ui : session.getUIs()) {
    if (!isUIActive(ui) && !ui.isClosing()) {
      ui.accessSynchronously(() -> {
        getLogger().debug("Closing inactive UI #{} in session {}",
            ui.getUIId(), sessionId);
        ui.close();
      });
    }
  }
}

相关文章