Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Latest commit

 

History

History
29 lines (22 loc) · 866 Bytes

tutorial-component-integration.asciidoc

File metadata and controls

29 lines (22 loc) · 866 Bytes
title order layout
Detecting Component Mappings
8
page

Detecting Component Mappings

You can detect whether a component is part of a template using the isTemplateMapped method.

This is useful if you want to execute custom logic depending on whether the component was mapped in a template (injected via the @Id or annotation) or created directly using one of its constructors, for example.

Example: Calling the isTemplateMapped method in MyComponent.

@Tag("div")
public class MyComponent extends Div {

  public MyComponent() {
    if (!isTemplateMapped()) {
      getElement().getStyle().set("color", "red");
    }
  }
}
  • By default, the component only sets a style when the component is not part of a template.

See Binding Template Components for more about To @Id mappings.