com.vaadin.flow.dom.Element.getAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(152)

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

Element.getAttribute介绍

[英]Gets the value of the given attribute.

Attribute names are considered case insensitive and all names will be converted to lower case automatically.

An attribute always has a String key and a String value.

Note that for attribute class the contents of the #getClassList() collection are returned as a single concatenated string.

Note that for attribute style the contents of the #getStyle() object are returned as a single concatenated string.

Note that attribute changes made on the server are sent to the client but attribute changes made on the client side are not reflected back to the server.
[中]获取给定属性的值。
属性名称不区分大小写,所有名称将自动转换为小写。
属性始终具有字符串键和字符串值。
请注意,对于属性class,#getClassList()集合的内容作为单个串联字符串返回。
请注意,对于属性style,#getStyle()对象的内容作为单个串联字符串返回。
请注意,在服务器上所做的属性更改会发送到客户端,但在客户端所做的属性更改不会反映回服务器。

代码示例

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

/**
 * Gets the theme names for this component.
 *
 * @return a space-separated string of theme names, empty string if there
 *         are no theme names or <code>null</code> if attribute (theme) is
 *         not set at all
 */
default String getThemeName() {
  return getElement().getAttribute("theme");
}

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

String attributeValue = element.getAttribute(name);
if ("".equals(attributeValue)) {
  target.attr(name, true);

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

/**
 * Gets the CSS class names for this component.
 *
 * @return a space-separated string of class names, or <code>null</code> if
 *         there are no class names
 */
default String getClassName() {
  return getElement().getAttribute("class");
}

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

/**
 * Get the component title text.
 * @return the component title
 */
public String getTitle() {
  return getElement().getAttribute("title");
}

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

/**
 * Creates new theme list for element specified.
 * 
 * @param element
 *            the element to reflect theme changes onto
 */
public ThemeListImpl(Element element) {
  this.element = element;
  themes = Optional.ofNullable(element.getAttribute(THEME_ATTRIBUTE_NAME))
      .map(value -> value.split(THEME_NAMES_DELIMITER))
      .map(Stream::of)
      .map(stream -> stream.filter(themeName -> !themeName.isEmpty())
          .collect(Collectors.toSet()))
      .orElseGet(HashSet::new);
}

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

/**
   * Checks if the field has {@code autocorrect} enabled.
   *
   * @return true if the field has {@code autocorrect} enabled
   */
  default boolean isAutocorrect() {
    String autocorrect = getElement().getAttribute(AUTOCORRECT_ATTRIBUTE);
    if (autocorrect == null || "".equals(autocorrect)) {
      return false;
    } else {
      return "on".equals(autocorrect);
    }
  }
}

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

private Optional<Element> getElementById(String id) {
  return getShadowRoot().getChildren().flatMap(this::flattenChildren)
      .filter(element -> id.equals(element.getAttribute("id")))
      .findFirst();
}

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

private void removeElementsAtSlot(String slot) {
  getElement().getChildren()
      .filter(child -> slot.equals(child.getAttribute("slot")))
      .forEach(Element::removeFromParent);
}

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

private Component getComponentAtSlot(String slot) {
  return getElement().getChildren()
      .filter(child -> slot.equals(child.getAttribute("slot")))
      .filter(child -> child.getComponent().isPresent())
      .map(child -> child.getComponent().get()).findFirst()
      .orElse(null);
}

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

/**
 * Gets all the child elements of the parent that are in the specified slot.
 * 
 * @param parent
 *            the component to get children from, not {@code null}
 * @param slot
 *            the name of the slot inside the parent, not {@code null}
 * @return the child elements of the parent that are inside the slot
 */
public static Stream<Element> getElementsInSlot(HasElement parent,
    String slot) {
  return parent.getElement().getChildren()
      .filter(child -> slot.equals(child.getAttribute("slot")));
}

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

/**
   * Gets the {@link Autocomplete} option of the field.
   *
   * @return the {@code autocomplete} value, or {@code null} if not set
   */
  default Autocomplete getAutocomplete() {
    String autocomplete = getElement().getAttribute(AUTOCOMPLETE_ATTRIBUTE);
    if (autocomplete == null) {
      return null;
    } else if ("".equals(autocomplete)) {
      // Default behavior for empty attribute.
      return Autocomplete.OFF;
    } else {
      return Autocomplete
          .valueOf(autocomplete.toUpperCase().replaceAll("-", "_"));
    }
  }
}

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

/**
   * Gets the {@link Autocapitalize} for indicating whether the value of this
   * component can be automatically completed by the browser.
   *
   * @return the {@code autocapitalize} value, or {@code null} if not set
   */
  default Autocapitalize getAutocapitalize() {
    String autocapitalize = getElement()
        .getAttribute(AUTOCAPITALIZE_ATTRIBUTE);
    if (autocapitalize == null) {
      // Not set, may inherit behavior from parent form.
      return null;
    } else if ("".equals(autocapitalize)) {
      // Default behavior for empty attribute.
      return Autocapitalize.SENTENCES;
    } else {
      return Autocapitalize.valueOf(autocapitalize.toUpperCase());
    }
  }
}

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

public void setIcon(Icon icon) {
  this.icon = icon;
  this.setIcon(icon.getElement().getAttribute("icon"));
}

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

public void setIcon(Icon icon) {
  button.setIcon(icon.getElement().getAttribute("icon"));
}

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

/**
 * Sets the content of the toolbar.
 * Any content with the attribute `new-button` triggers a new item creation.
 *
 * @param components the content to be set
 */
public void setToolbar(Component... components) {
  final Element[] existingToolbarElements = getElement().getChildren()
      .filter(e -> TOOLBAR_SLOT_NAME.equals(e.getAttribute(SLOT_KEY)))
      .toArray(Element[]::new);
  getElement().removeChild(existingToolbarElements);
  final Element[] newToolbarElements = Arrays.stream(components)
      .map(Component::getElement)
      .map(e -> e.setAttribute(SLOT_KEY, TOOLBAR_SLOT_NAME))
      .toArray(Element[]::new);
  getElement().appendChild(newToolbarElements);
}

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

String attribute = getElement().getAttribute("tabindex");
if (attribute == null || attribute.isEmpty()) {
  throw new IllegalStateException(

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

/**
 * Helper for creating an attribute descriptor with a specific return value
 * wrapper.
 *
 * @param name
 *            the name of the element attribute, not <code>null</code>
 * @param defaultValue
 *            the default value of the property, not <code>null</code>
 * @param removeDefault
 *            if {@code true} then attribute with default value will be
 *            removed, otherwise attribute with the default value will be
 *            kept as is
 * @param returnWrapper
 *            a callback that returns the actual value given the attribute
 *            value and the default value
 * @return a property descriptor, not <code>null</code>
 */
private static <T> PropertyDescriptor<String, T> attribute(String name,
    String defaultValue, boolean removeDefault,
    BiFunction<String, String, T> returnWrapper) {
  return new PropertyDescriptorImpl<>(name, defaultValue,
      (element, value) -> element.setAttribute(name, value),
      removeDefault ? element -> element.removeAttribute(name)
          : element -> element.setAttribute(name, defaultValue),
      element -> element.getAttribute(name), returnWrapper);
}

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

public PaperBadge(Component bind, String icon, String label) {
  if (icon != null) {
    getElement().setAttribute("icon", icon);
  }
  if (label != null) {
    setText(label);
  }
  getElement().setAttribute("for", bind.getElement().getAttribute("id"));
}

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

public NavigationBadgeIconButton(String name, Icon icon) {
  super(name, icon.getElement().getAttribute("icon"));
  setId("menu-btn-" + idCounter++);
  badge = new MenuBadgeComponent();
  badge.setVisible(false);
  add(badge);
  getItem().getElement().getStyle().set("white-space", "nowrap");
}

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

public IconButton(Icon icon, ComponentEventListener<ClickEvent<PaperIconButton>> listener) {
  setId("menu-btn-" + idCounter++);
  setWidth("var(--app-layout-menu-button-height)");
  setHeight("var(--app-layout-menu-button-height)");
  button = new PaperIconButton(icon.getElement().getAttribute("icon"));
  button.getElement().getStyle()
      .set("width", "100%")
      .set("height", "100%");
  button.getElement().setAttribute("id", "button");
  add(button);
  if (listener != null) {
    button.setClickListener(listener);
  }
}

相关文章

微信公众号

最新文章

更多