Skip to content

Many-to-Many Tree Reference TAB_TREE

Displays options in a tree selection panel. Checking nodes establishes a many-to-many relationship, corresponding to JPA @ManyToMany. Suitable when the referenced data has a hierarchical structure.

tab-tree

Basic Usage

java
@ManyToMany
@JoinTable(name = "rel_main_tree",
    joinColumns = @JoinColumn(name = "main_id"),
    inverseJoinColumns = @JoinColumn(name = "tree_id"))
@EruptField(
    edit = @Edit(title = "Related Tree", type = EditType.TAB_TREE)
)
private Set<TreeEntity> treeItems;

The referenced entity declares its own hierarchy through @Erupt(tree = @Tree(...)):

java
@Entity
@Erupt(name = "Tree Entity", tree = @Tree(pid = "parent.id"))
public class TreeEntity extends BaseModel {

    @EruptField(
        views = @View(title = "Name"),
        edit = @Edit(title = "Name")
    )
    private String name;

    @ManyToOne
    private TreeEntity parent;
}

Configuration

TAB_TREE has no dedicated sub-annotation on @Edit. Both the data source and the hierarchy come entirely from the referenced entity's own @Erupt(tree = @Tree(...)). The backend endpoint /erupt-api/data/tab/tree/{erupt}/{field} reads exactly that @Tree configuration.

@Tree options:

AttributeTypeDefaultDescription
idString"id"Tree node storage column
labelString"name"Tree node display column
pidString""Parent node identifier column; if omitted the data is rendered as a flat list
expandLevelint999Number of levels expanded by default
rootPid@Expr@ExprIdentifies what characteristic of pid marks a root node; must be used together with filter

See @Tree annotation for details.

Notes

WARNING

  • The field must be a generic collection (e.g. Set<TreeEntity> / List<TreeEntity>); the framework extracts the referenced erupt entity from the generic type. Otherwise startup fails with Component modification field is incorrect.
  • TAB_TREE does not support Excel import/export (excelOperator = false).

Option filtering reuses @Edit(filter = ...); each value (or the expression returned by conditionHandler, when configured) is appended as a query condition on the tree data endpoint:

java
@ManyToMany
@EruptField(
    edit = @Edit(
        title = "Menu Permission",
        type = EditType.TAB_TREE,
        filter = @Filter(conditionHandler = RoleMenuFilter.class)
    )
)
private Set<EruptMenu> menus;

A real built-in example is EruptRole.menus, whose referenced entity EruptMenu declares tree = @Tree(pid = "parentMenu.id", expandLevel = 5).

Contributors

The avatar of contributor named as YuePeng YuePeng
The avatar of contributor named as Claude Opus 5 (1M context) Claude Opus 5 (1M context)

Changelog

Released under the Apache-2.0 License.