TagField allows you to display the selected values as tags. This component is based on SuggestionField and has similar functionality, but one significant difference is that TagField allows you to select multiple values instead of a single value. You can also use TagPicker for work with tags.

tag field

Component’s XML-name: tagField.


Use TagField if:

  • You need to display selected values as tags.

  • You need to select multiple options.

  • The number of options in the list of suggested values is too large to use CheckBoxGroup.

  • You want to provide high-performance search in the database without loading much data to the UI layer.

To enable TagField suggestions, you should use the search executor.


TagField has all specific attributes of the SuggestionField:

and one special attribute:

  • clearAllVisible - responsible for displaying the button that deletes all previously selected values. By default, clearAllVisible = "false".

Creating New Items

TagField has ENTER keypress handler and a predefined class NewTagProvider for converting entered text to tag. In the example below, we convert entered text to entity:

@Table(name = "UIEX1_DEPARTMENT")
@Entity(name = "uiex1_Department")
public class Department {
    @Column(name = "NAME")
    private String name;

    @OneToMany(mappedBy = "department")
    private List<Employee> employee;
@Table(name = "UIEX1_EMPLOYEE")
@Entity(name = "uiex1_Employee")
public class Employee {
    @Column(name = "NAME")
    private String name;

    @JoinColumn(name = "DEPARTMENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Department department;
    <instance id="departmentDc"
        <fetchPlan extends="_base">
            <property name="employee" fetchPlan="_base"/>
    <tagField id="employeesTagField"
              caption="Department employees" />
private TagField<Employee> employeesTagField;
private Metadata metadata;

public void onInit(InitEvent event) {
    employeesTagField.setEnterPressHandler(new TagField.NewTagProvider<Employee>() {
        public Employee create(String name) {
            Employee employee = metadata.create(Employee.class);
            return employee;



To change the displayed caption of tags, TagField has TagCaptionProvider.

@Install(to = "employeesTagField", subject = "tagCaptionProvider")
private String employeesTagFieldTagCaptionProvider(Employee employee) {
    return employee.getName() + ", salary: " + employee.getSalary();
tag field caption


This listener allows you to handle clicks on tags. For example, you can programmatically set the edit screen to open for the tag that the user clicked on:

private ScreenBuilders screenBuilders;

public void onEmployeesTagFieldTagClick(TagField.TagClickEvent<Employee> event) {
    screenBuilders.editor(Employee.class, this)


TagComparator allows you to sort tags. For example, you can sort employees by their salaries, in descending order:

private TagField<Employee> employeesTagField;

public void onInit(InitEvent event) {
    employeesTagField.setTagComparator((o1, o2) -> {
        Double salary1 = o1.getSalary();
        Double salary2 = o2.getSalary();
        if (salary1 == null) {
            return 1;
        } else if (salary2 == null) {
            return -1;
        return salary2.compareTo(salary1);


TagStyleProvider allows managing additional style for the tags:

@Install(to = "employeesTagField", subject = "tagStyleProvider")
private String employeesTagFieldTagStyleProvider(Employee employee) {
    if (employee != null) {
        switch (employee.getPosition()) {
            case DEV:
                return "developer";
            case BA:
                return "business-analyst";
            case PM:
                return "project-manager";
            case CEO:
                return "chief-executive-officer";
    return null;

Then you should define the item styles set in the application theme. Detailed information on creating a theme is available in Themes. Style names representing in the controller, together with prefixes identifying each item, form CSS selectors. For example:

.jmix-taglabel.developer {
  background-color: green;
  color: black;

.jmix-taglabel.business-analyst {
  background-color: orange;
  color: black;

.jmix-taglabel.project-manager {
  background-color: darkorchid;
  color: black;

.jmix-taglabel.chief-executive-officer {
  background-color: tomato;
  color: black;
tag field style